1 /* Building internal representation for IRA.
2 Copyright (C) 2006-2015 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"
30 #include "insn-config.h"
34 #include "diagnostic-core.h"
38 #include "sparseset.h"
41 static ira_copy_t
find_allocno_copy (ira_allocno_t
, ira_allocno_t
, rtx_insn
*,
42 ira_loop_tree_node_t
);
44 /* The root of the loop tree corresponding to the all function. */
45 ira_loop_tree_node_t ira_loop_tree_root
;
47 /* Height of the loop tree. */
48 int ira_loop_tree_height
;
50 /* All nodes representing basic blocks are referred through the
51 following array. We can not use basic block member `aux' for this
52 because it is used for insertion of insns on edges. */
53 ira_loop_tree_node_t ira_bb_nodes
;
55 /* All nodes representing loops are referred through the following
57 ira_loop_tree_node_t ira_loop_nodes
;
59 /* And size of the ira_loop_nodes array. */
60 unsigned int ira_loop_nodes_count
;
62 /* Map regno -> allocnos with given regno (see comments for
63 allocno member `next_regno_allocno'). */
64 ira_allocno_t
*ira_regno_allocno_map
;
66 /* Array of references to all allocnos. The order number of the
67 allocno corresponds to the index in the array. Removed allocnos
68 have NULL element value. */
69 ira_allocno_t
*ira_allocnos
;
71 /* Sizes of the previous array. */
74 /* Count of conflict record structures we've created, used when creating
78 /* Map a conflict id to its conflict record. */
79 ira_object_t
*ira_object_id_map
;
81 /* Array of references to all allocno preferences. The order number
82 of the preference corresponds to the index in the array. */
83 ira_pref_t
*ira_prefs
;
85 /* Size of the previous array. */
88 /* Array of references to all copies. The order number of the copy
89 corresponds to the index in the array. Removed copies have NULL
91 ira_copy_t
*ira_copies
;
93 /* Size of the previous array. */
98 /* LAST_BASIC_BLOCK before generating additional insns because of live
99 range splitting. Emitting insns on a critical edge creates a new
101 static int last_basic_block_before_change
;
103 /* Initialize some members in loop tree node NODE. Use LOOP_NUM for
104 the member loop_num. */
106 init_loop_tree_node (struct ira_loop_tree_node
*node
, int loop_num
)
108 int max_regno
= max_reg_num ();
110 node
->regno_allocno_map
111 = (ira_allocno_t
*) ira_allocate (sizeof (ira_allocno_t
) * max_regno
);
112 memset (node
->regno_allocno_map
, 0, sizeof (ira_allocno_t
) * max_regno
);
113 memset (node
->reg_pressure
, 0, sizeof (node
->reg_pressure
));
114 node
->all_allocnos
= ira_allocate_bitmap ();
115 node
->modified_regnos
= ira_allocate_bitmap ();
116 node
->border_allocnos
= ira_allocate_bitmap ();
117 node
->local_copies
= ira_allocate_bitmap ();
118 node
->loop_num
= loop_num
;
119 node
->children
= NULL
;
120 node
->subloops
= NULL
;
124 /* The following function allocates the loop tree nodes. If
125 CURRENT_LOOPS is NULL, the nodes corresponding to the loops (except
126 the root which corresponds the all function) will be not allocated
127 but nodes will still be allocated for basic blocks. */
129 create_loop_tree_nodes (void)
139 = ((struct ira_loop_tree_node
*)
140 ira_allocate (sizeof (struct ira_loop_tree_node
)
141 * last_basic_block_for_fn (cfun
)));
142 last_basic_block_before_change
= last_basic_block_for_fn (cfun
);
143 for (i
= 0; i
< (unsigned int) last_basic_block_for_fn (cfun
); i
++)
145 ira_bb_nodes
[i
].regno_allocno_map
= NULL
;
146 memset (ira_bb_nodes
[i
].reg_pressure
, 0,
147 sizeof (ira_bb_nodes
[i
].reg_pressure
));
148 ira_bb_nodes
[i
].all_allocnos
= NULL
;
149 ira_bb_nodes
[i
].modified_regnos
= NULL
;
150 ira_bb_nodes
[i
].border_allocnos
= NULL
;
151 ira_bb_nodes
[i
].local_copies
= NULL
;
153 if (current_loops
== NULL
)
155 ira_loop_nodes_count
= 1;
156 ira_loop_nodes
= ((struct ira_loop_tree_node
*)
157 ira_allocate (sizeof (struct ira_loop_tree_node
)));
158 init_loop_tree_node (ira_loop_nodes
, 0);
161 ira_loop_nodes_count
= number_of_loops (cfun
);
162 ira_loop_nodes
= ((struct ira_loop_tree_node
*)
163 ira_allocate (sizeof (struct ira_loop_tree_node
)
164 * ira_loop_nodes_count
));
165 FOR_EACH_VEC_SAFE_ELT (get_loops (cfun
), i
, loop
)
167 if (loop_outer (loop
) != NULL
)
169 ira_loop_nodes
[i
].regno_allocno_map
= NULL
;
171 FOR_EACH_EDGE (e
, ei
, loop
->header
->preds
)
172 if (e
->src
!= loop
->latch
173 && (e
->flags
& EDGE_ABNORMAL
) && EDGE_CRITICAL_P (e
))
180 edges
= get_loop_exit_edges (loop
);
181 FOR_EACH_VEC_ELT (edges
, j
, e
)
182 if ((e
->flags
& EDGE_ABNORMAL
) && EDGE_CRITICAL_P (e
))
191 init_loop_tree_node (&ira_loop_nodes
[i
], loop
->num
);
195 /* The function returns TRUE if there are more one allocation
198 more_one_region_p (void)
203 if (current_loops
!= NULL
)
204 FOR_EACH_VEC_SAFE_ELT (get_loops (cfun
), i
, loop
)
205 if (ira_loop_nodes
[i
].regno_allocno_map
!= NULL
206 && ira_loop_tree_root
!= &ira_loop_nodes
[i
])
211 /* Free the loop tree node of a loop. */
213 finish_loop_tree_node (ira_loop_tree_node_t loop
)
215 if (loop
->regno_allocno_map
!= NULL
)
217 ira_assert (loop
->bb
== NULL
);
218 ira_free_bitmap (loop
->local_copies
);
219 ira_free_bitmap (loop
->border_allocnos
);
220 ira_free_bitmap (loop
->modified_regnos
);
221 ira_free_bitmap (loop
->all_allocnos
);
222 ira_free (loop
->regno_allocno_map
);
223 loop
->regno_allocno_map
= NULL
;
227 /* Free the loop tree nodes. */
229 finish_loop_tree_nodes (void)
233 for (i
= 0; i
< ira_loop_nodes_count
; i
++)
234 finish_loop_tree_node (&ira_loop_nodes
[i
]);
235 ira_free (ira_loop_nodes
);
236 for (i
= 0; i
< (unsigned int) last_basic_block_before_change
; i
++)
238 if (ira_bb_nodes
[i
].local_copies
!= NULL
)
239 ira_free_bitmap (ira_bb_nodes
[i
].local_copies
);
240 if (ira_bb_nodes
[i
].border_allocnos
!= NULL
)
241 ira_free_bitmap (ira_bb_nodes
[i
].border_allocnos
);
242 if (ira_bb_nodes
[i
].modified_regnos
!= NULL
)
243 ira_free_bitmap (ira_bb_nodes
[i
].modified_regnos
);
244 if (ira_bb_nodes
[i
].all_allocnos
!= NULL
)
245 ira_free_bitmap (ira_bb_nodes
[i
].all_allocnos
);
246 if (ira_bb_nodes
[i
].regno_allocno_map
!= NULL
)
247 ira_free (ira_bb_nodes
[i
].regno_allocno_map
);
249 ira_free (ira_bb_nodes
);
254 /* The following recursive function adds LOOP to the loop tree
255 hierarchy. LOOP is added only once. If LOOP is NULL we adding
256 loop designating the whole function when CFG loops are not
259 add_loop_to_tree (struct loop
*loop
)
263 ira_loop_tree_node_t loop_node
, parent_node
;
265 /* We can not use loop node access macros here because of potential
266 checking and because the nodes are not initialized enough
268 if (loop
!= NULL
&& loop_outer (loop
) != NULL
)
269 add_loop_to_tree (loop_outer (loop
));
270 loop_num
= loop
!= NULL
? loop
->num
: 0;
271 if (ira_loop_nodes
[loop_num
].regno_allocno_map
!= NULL
272 && ira_loop_nodes
[loop_num
].children
== NULL
)
274 /* We have not added loop node to the tree yet. */
275 loop_node
= &ira_loop_nodes
[loop_num
];
276 loop_node
->loop
= loop
;
277 loop_node
->bb
= NULL
;
282 for (parent
= loop_outer (loop
);
284 parent
= loop_outer (parent
))
285 if (ira_loop_nodes
[parent
->num
].regno_allocno_map
!= NULL
)
290 loop_node
->next
= NULL
;
291 loop_node
->subloop_next
= NULL
;
292 loop_node
->parent
= NULL
;
296 parent_node
= &ira_loop_nodes
[parent
->num
];
297 loop_node
->next
= parent_node
->children
;
298 parent_node
->children
= loop_node
;
299 loop_node
->subloop_next
= parent_node
->subloops
;
300 parent_node
->subloops
= loop_node
;
301 loop_node
->parent
= parent_node
;
306 /* The following recursive function sets up levels of nodes of the
307 tree given its root LOOP_NODE. The enumeration starts with LEVEL.
308 The function returns maximal value of level in the tree + 1. */
310 setup_loop_tree_level (ira_loop_tree_node_t loop_node
, int level
)
312 int height
, max_height
;
313 ira_loop_tree_node_t subloop_node
;
315 ira_assert (loop_node
->bb
== NULL
);
316 loop_node
->level
= level
;
317 max_height
= level
+ 1;
318 for (subloop_node
= loop_node
->subloops
;
319 subloop_node
!= NULL
;
320 subloop_node
= subloop_node
->subloop_next
)
322 ira_assert (subloop_node
->bb
== NULL
);
323 height
= setup_loop_tree_level (subloop_node
, level
+ 1);
324 if (height
> max_height
)
330 /* Create the loop tree. The algorithm is designed to provide correct
331 order of loops (they are ordered by their last loop BB) and basic
332 blocks in the chain formed by member next. */
334 form_loop_tree (void)
338 ira_loop_tree_node_t bb_node
, loop_node
;
340 /* We can not use loop/bb node access macros because of potential
341 checking and because the nodes are not initialized enough
343 FOR_EACH_BB_FN (bb
, cfun
)
345 bb_node
= &ira_bb_nodes
[bb
->index
];
347 bb_node
->loop
= NULL
;
348 bb_node
->subloops
= NULL
;
349 bb_node
->children
= NULL
;
350 bb_node
->subloop_next
= NULL
;
351 bb_node
->next
= NULL
;
352 if (current_loops
== NULL
)
356 for (parent
= bb
->loop_father
;
358 parent
= loop_outer (parent
))
359 if (ira_loop_nodes
[parent
->num
].regno_allocno_map
!= NULL
)
362 add_loop_to_tree (parent
);
363 loop_node
= &ira_loop_nodes
[parent
== NULL
? 0 : parent
->num
];
364 bb_node
->next
= loop_node
->children
;
365 bb_node
->parent
= loop_node
;
366 loop_node
->children
= bb_node
;
368 ira_loop_tree_root
= IRA_LOOP_NODE_BY_INDEX (0);
369 ira_loop_tree_height
= setup_loop_tree_level (ira_loop_tree_root
, 0);
370 ira_assert (ira_loop_tree_root
->regno_allocno_map
!= NULL
);
375 /* Rebuild IRA_REGNO_ALLOCNO_MAP and REGNO_ALLOCNO_MAPs of the loop
378 rebuild_regno_allocno_maps (void)
381 int max_regno
, regno
;
383 ira_loop_tree_node_t loop_tree_node
;
385 ira_allocno_iterator ai
;
387 ira_assert (current_loops
!= NULL
);
388 max_regno
= max_reg_num ();
389 FOR_EACH_VEC_SAFE_ELT (get_loops (cfun
), l
, loop
)
390 if (ira_loop_nodes
[l
].regno_allocno_map
!= NULL
)
392 ira_free (ira_loop_nodes
[l
].regno_allocno_map
);
393 ira_loop_nodes
[l
].regno_allocno_map
394 = (ira_allocno_t
*) ira_allocate (sizeof (ira_allocno_t
)
396 memset (ira_loop_nodes
[l
].regno_allocno_map
, 0,
397 sizeof (ira_allocno_t
) * max_regno
);
399 ira_free (ira_regno_allocno_map
);
400 ira_regno_allocno_map
401 = (ira_allocno_t
*) ira_allocate (max_regno
* sizeof (ira_allocno_t
));
402 memset (ira_regno_allocno_map
, 0, max_regno
* sizeof (ira_allocno_t
));
403 FOR_EACH_ALLOCNO (a
, ai
)
405 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
406 /* Caps are not in the regno allocno maps. */
408 regno
= ALLOCNO_REGNO (a
);
409 loop_tree_node
= ALLOCNO_LOOP_TREE_NODE (a
);
410 ALLOCNO_NEXT_REGNO_ALLOCNO (a
) = ira_regno_allocno_map
[regno
];
411 ira_regno_allocno_map
[regno
] = a
;
412 if (loop_tree_node
->regno_allocno_map
[regno
] == NULL
)
413 /* Remember that we can create temporary allocnos to break
414 cycles in register shuffle. */
415 loop_tree_node
->regno_allocno_map
[regno
] = a
;
420 /* Pools for allocnos, allocno live ranges and objects. */
421 static object_allocator
<live_range
> live_range_pool ("live ranges");
422 static object_allocator
<ira_allocno
> allocno_pool ("allocnos");
423 static object_allocator
<ira_object
> object_pool ("objects");
425 /* Vec containing references to all created allocnos. It is a
426 container of array allocnos. */
427 static vec
<ira_allocno_t
> allocno_vec
;
429 /* Vec containing references to all created ira_objects. It is a
430 container of ira_object_id_map. */
431 static vec
<ira_object_t
> ira_object_id_map_vec
;
433 /* Initialize data concerning allocnos. */
435 initiate_allocnos (void)
437 allocno_vec
.create (max_reg_num () * 2);
439 ira_allocnos_num
= 0;
441 ira_object_id_map_vec
.create (max_reg_num () * 2);
442 ira_object_id_map
= NULL
;
443 ira_regno_allocno_map
444 = (ira_allocno_t
*) ira_allocate (max_reg_num ()
445 * sizeof (ira_allocno_t
));
446 memset (ira_regno_allocno_map
, 0, max_reg_num () * sizeof (ira_allocno_t
));
449 /* Create and return an object corresponding to a new allocno A. */
451 ira_create_object (ira_allocno_t a
, int subword
)
453 enum reg_class aclass
= ALLOCNO_CLASS (a
);
454 ira_object_t obj
= object_pool
.allocate ();
456 OBJECT_ALLOCNO (obj
) = a
;
457 OBJECT_SUBWORD (obj
) = subword
;
458 OBJECT_CONFLICT_ID (obj
) = ira_objects_num
;
459 OBJECT_CONFLICT_VEC_P (obj
) = false;
460 OBJECT_CONFLICT_ARRAY (obj
) = NULL
;
461 OBJECT_NUM_CONFLICTS (obj
) = 0;
462 COPY_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
), ira_no_alloc_regs
);
463 COPY_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
), ira_no_alloc_regs
);
464 IOR_COMPL_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
),
465 reg_class_contents
[aclass
]);
466 IOR_COMPL_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
),
467 reg_class_contents
[aclass
]);
468 OBJECT_MIN (obj
) = INT_MAX
;
469 OBJECT_MAX (obj
) = -1;
470 OBJECT_LIVE_RANGES (obj
) = NULL
;
472 ira_object_id_map_vec
.safe_push (obj
);
474 = ira_object_id_map_vec
.address ();
475 ira_objects_num
= ira_object_id_map_vec
.length ();
480 /* Create and return the allocno corresponding to REGNO in
481 LOOP_TREE_NODE. Add the allocno to the list of allocnos with the
482 same regno if CAP_P is FALSE. */
484 ira_create_allocno (int regno
, bool cap_p
,
485 ira_loop_tree_node_t loop_tree_node
)
489 a
= allocno_pool
.allocate ();
490 ALLOCNO_REGNO (a
) = regno
;
491 ALLOCNO_LOOP_TREE_NODE (a
) = loop_tree_node
;
494 ALLOCNO_NEXT_REGNO_ALLOCNO (a
) = ira_regno_allocno_map
[regno
];
495 ira_regno_allocno_map
[regno
] = a
;
496 if (loop_tree_node
->regno_allocno_map
[regno
] == NULL
)
497 /* Remember that we can create temporary allocnos to break
498 cycles in register shuffle on region borders (see
500 loop_tree_node
->regno_allocno_map
[regno
] = a
;
502 ALLOCNO_CAP (a
) = NULL
;
503 ALLOCNO_CAP_MEMBER (a
) = NULL
;
504 ALLOCNO_NUM (a
) = ira_allocnos_num
;
505 bitmap_set_bit (loop_tree_node
->all_allocnos
, ALLOCNO_NUM (a
));
506 ALLOCNO_NREFS (a
) = 0;
507 ALLOCNO_FREQ (a
) = 0;
508 ALLOCNO_HARD_REGNO (a
) = -1;
509 ALLOCNO_CALL_FREQ (a
) = 0;
510 ALLOCNO_CALLS_CROSSED_NUM (a
) = 0;
511 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
) = 0;
512 CLEAR_HARD_REG_SET (ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
));
514 ALLOCNO_NO_STACK_REG_P (a
) = false;
515 ALLOCNO_TOTAL_NO_STACK_REG_P (a
) = false;
517 ALLOCNO_DONT_REASSIGN_P (a
) = false;
518 ALLOCNO_BAD_SPILL_P (a
) = false;
519 ALLOCNO_ASSIGNED_P (a
) = false;
520 ALLOCNO_MODE (a
) = (regno
< 0 ? VOIDmode
: PSEUDO_REGNO_MODE (regno
));
521 ALLOCNO_WMODE (a
) = ALLOCNO_MODE (a
);
522 ALLOCNO_PREFS (a
) = NULL
;
523 ALLOCNO_COPIES (a
) = NULL
;
524 ALLOCNO_HARD_REG_COSTS (a
) = NULL
;
525 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) = NULL
;
526 ALLOCNO_UPDATED_HARD_REG_COSTS (a
) = NULL
;
527 ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) = NULL
;
528 ALLOCNO_CLASS (a
) = NO_REGS
;
529 ALLOCNO_UPDATED_CLASS_COST (a
) = 0;
530 ALLOCNO_CLASS_COST (a
) = 0;
531 ALLOCNO_MEMORY_COST (a
) = 0;
532 ALLOCNO_UPDATED_MEMORY_COST (a
) = 0;
533 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
) = 0;
534 ALLOCNO_NUM_OBJECTS (a
) = 0;
536 ALLOCNO_ADD_DATA (a
) = NULL
;
537 allocno_vec
.safe_push (a
);
538 ira_allocnos
= allocno_vec
.address ();
539 ira_allocnos_num
= allocno_vec
.length ();
544 /* Set up register class for A and update its conflict hard
547 ira_set_allocno_class (ira_allocno_t a
, enum reg_class aclass
)
549 ira_allocno_object_iterator oi
;
552 ALLOCNO_CLASS (a
) = aclass
;
553 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
555 IOR_COMPL_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
),
556 reg_class_contents
[aclass
]);
557 IOR_COMPL_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
),
558 reg_class_contents
[aclass
]);
562 /* Determine the number of objects we should associate with allocno A
563 and allocate them. */
565 ira_create_allocno_objects (ira_allocno_t a
)
567 machine_mode mode
= ALLOCNO_MODE (a
);
568 enum reg_class aclass
= ALLOCNO_CLASS (a
);
569 int n
= ira_reg_class_max_nregs
[aclass
][mode
];
572 if (GET_MODE_SIZE (mode
) != 2 * UNITS_PER_WORD
|| n
!= 2)
575 ALLOCNO_NUM_OBJECTS (a
) = n
;
576 for (i
= 0; i
< n
; i
++)
577 ALLOCNO_OBJECT (a
, i
) = ira_create_object (a
, i
);
580 /* For each allocno, set ALLOCNO_NUM_OBJECTS and create the
581 ALLOCNO_OBJECT structures. This must be called after the allocno
582 classes are known. */
584 create_allocno_objects (void)
587 ira_allocno_iterator ai
;
589 FOR_EACH_ALLOCNO (a
, ai
)
590 ira_create_allocno_objects (a
);
593 /* Merge hard register conflict information for all objects associated with
594 allocno TO into the corresponding objects associated with FROM.
595 If TOTAL_ONLY is true, we only merge OBJECT_TOTAL_CONFLICT_HARD_REGS. */
597 merge_hard_reg_conflicts (ira_allocno_t from
, ira_allocno_t to
,
601 gcc_assert (ALLOCNO_NUM_OBJECTS (to
) == ALLOCNO_NUM_OBJECTS (from
));
602 for (i
= 0; i
< ALLOCNO_NUM_OBJECTS (to
); i
++)
604 ira_object_t from_obj
= ALLOCNO_OBJECT (from
, i
);
605 ira_object_t to_obj
= ALLOCNO_OBJECT (to
, i
);
608 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (to_obj
),
609 OBJECT_CONFLICT_HARD_REGS (from_obj
));
610 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (to_obj
),
611 OBJECT_TOTAL_CONFLICT_HARD_REGS (from_obj
));
614 if (!total_only
&& ALLOCNO_NO_STACK_REG_P (from
))
615 ALLOCNO_NO_STACK_REG_P (to
) = true;
616 if (ALLOCNO_TOTAL_NO_STACK_REG_P (from
))
617 ALLOCNO_TOTAL_NO_STACK_REG_P (to
) = true;
621 /* Update hard register conflict information for all objects associated with
622 A to include the regs in SET. */
624 ior_hard_reg_conflicts (ira_allocno_t a
, HARD_REG_SET
*set
)
626 ira_allocno_object_iterator i
;
629 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, i
)
631 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
), *set
);
632 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
), *set
);
636 /* Return TRUE if a conflict vector with NUM elements is more
637 profitable than a conflict bit vector for OBJ. */
639 ira_conflict_vector_profitable_p (ira_object_t obj
, int num
)
642 int max
= OBJECT_MAX (obj
);
643 int min
= OBJECT_MIN (obj
);
646 /* We prefer a bit vector in such case because it does not result
650 nw
= (max
- min
+ IRA_INT_BITS
) / IRA_INT_BITS
;
651 return (2 * sizeof (ira_object_t
) * (num
+ 1)
652 < 3 * nw
* sizeof (IRA_INT_TYPE
));
655 /* Allocates and initialize the conflict vector of OBJ for NUM
656 conflicting objects. */
658 ira_allocate_conflict_vec (ira_object_t obj
, int num
)
663 ira_assert (OBJECT_CONFLICT_ARRAY (obj
) == NULL
);
664 num
++; /* for NULL end marker */
665 size
= sizeof (ira_object_t
) * num
;
666 OBJECT_CONFLICT_ARRAY (obj
) = ira_allocate (size
);
667 vec
= (ira_object_t
*) OBJECT_CONFLICT_ARRAY (obj
);
669 OBJECT_NUM_CONFLICTS (obj
) = 0;
670 OBJECT_CONFLICT_ARRAY_SIZE (obj
) = size
;
671 OBJECT_CONFLICT_VEC_P (obj
) = true;
674 /* Allocate and initialize the conflict bit vector of OBJ. */
676 allocate_conflict_bit_vec (ira_object_t obj
)
680 ira_assert (OBJECT_CONFLICT_ARRAY (obj
) == NULL
);
681 size
= ((OBJECT_MAX (obj
) - OBJECT_MIN (obj
) + IRA_INT_BITS
)
682 / IRA_INT_BITS
* sizeof (IRA_INT_TYPE
));
683 OBJECT_CONFLICT_ARRAY (obj
) = ira_allocate (size
);
684 memset (OBJECT_CONFLICT_ARRAY (obj
), 0, size
);
685 OBJECT_CONFLICT_ARRAY_SIZE (obj
) = size
;
686 OBJECT_CONFLICT_VEC_P (obj
) = false;
689 /* Allocate and initialize the conflict vector or conflict bit vector
690 of OBJ for NUM conflicting allocnos whatever is more profitable. */
692 ira_allocate_object_conflicts (ira_object_t obj
, int num
)
694 if (ira_conflict_vector_profitable_p (obj
, num
))
695 ira_allocate_conflict_vec (obj
, num
);
697 allocate_conflict_bit_vec (obj
);
700 /* Add OBJ2 to the conflicts of OBJ1. */
702 add_to_conflicts (ira_object_t obj1
, ira_object_t obj2
)
707 if (OBJECT_CONFLICT_VEC_P (obj1
))
709 ira_object_t
*vec
= OBJECT_CONFLICT_VEC (obj1
);
710 int curr_num
= OBJECT_NUM_CONFLICTS (obj1
);
712 if (OBJECT_CONFLICT_ARRAY_SIZE (obj1
) < num
* sizeof (ira_object_t
))
714 ira_object_t
*newvec
;
715 size
= (3 * num
/ 2 + 1) * sizeof (ira_allocno_t
);
716 newvec
= (ira_object_t
*) ira_allocate (size
);
717 memcpy (newvec
, vec
, curr_num
* sizeof (ira_object_t
));
720 OBJECT_CONFLICT_ARRAY (obj1
) = vec
;
721 OBJECT_CONFLICT_ARRAY_SIZE (obj1
) = size
;
725 OBJECT_NUM_CONFLICTS (obj1
)++;
729 int nw
, added_head_nw
, id
;
730 IRA_INT_TYPE
*vec
= OBJECT_CONFLICT_BITVEC (obj1
);
732 id
= OBJECT_CONFLICT_ID (obj2
);
733 if (OBJECT_MIN (obj1
) > id
)
735 /* Expand head of the bit vector. */
736 added_head_nw
= (OBJECT_MIN (obj1
) - id
- 1) / IRA_INT_BITS
+ 1;
737 nw
= (OBJECT_MAX (obj1
) - OBJECT_MIN (obj1
)) / IRA_INT_BITS
+ 1;
738 size
= (nw
+ added_head_nw
) * sizeof (IRA_INT_TYPE
);
739 if (OBJECT_CONFLICT_ARRAY_SIZE (obj1
) >= size
)
741 memmove ((char *) vec
+ added_head_nw
* sizeof (IRA_INT_TYPE
),
742 vec
, nw
* sizeof (IRA_INT_TYPE
));
743 memset (vec
, 0, added_head_nw
* sizeof (IRA_INT_TYPE
));
748 = (3 * (nw
+ added_head_nw
) / 2 + 1) * sizeof (IRA_INT_TYPE
);
749 vec
= (IRA_INT_TYPE
*) ira_allocate (size
);
750 memcpy ((char *) vec
+ added_head_nw
* sizeof (IRA_INT_TYPE
),
751 OBJECT_CONFLICT_ARRAY (obj1
), nw
* sizeof (IRA_INT_TYPE
));
752 memset (vec
, 0, added_head_nw
* sizeof (IRA_INT_TYPE
));
754 + (nw
+ added_head_nw
) * sizeof (IRA_INT_TYPE
),
755 0, size
- (nw
+ added_head_nw
) * sizeof (IRA_INT_TYPE
));
756 ira_free (OBJECT_CONFLICT_ARRAY (obj1
));
757 OBJECT_CONFLICT_ARRAY (obj1
) = vec
;
758 OBJECT_CONFLICT_ARRAY_SIZE (obj1
) = size
;
760 OBJECT_MIN (obj1
) -= added_head_nw
* IRA_INT_BITS
;
762 else if (OBJECT_MAX (obj1
) < id
)
764 nw
= (id
- OBJECT_MIN (obj1
)) / IRA_INT_BITS
+ 1;
765 size
= nw
* sizeof (IRA_INT_TYPE
);
766 if (OBJECT_CONFLICT_ARRAY_SIZE (obj1
) < size
)
768 /* Expand tail of the bit vector. */
769 size
= (3 * nw
/ 2 + 1) * sizeof (IRA_INT_TYPE
);
770 vec
= (IRA_INT_TYPE
*) ira_allocate (size
);
771 memcpy (vec
, OBJECT_CONFLICT_ARRAY (obj1
), OBJECT_CONFLICT_ARRAY_SIZE (obj1
));
772 memset ((char *) vec
+ OBJECT_CONFLICT_ARRAY_SIZE (obj1
),
773 0, size
- OBJECT_CONFLICT_ARRAY_SIZE (obj1
));
774 ira_free (OBJECT_CONFLICT_ARRAY (obj1
));
775 OBJECT_CONFLICT_ARRAY (obj1
) = vec
;
776 OBJECT_CONFLICT_ARRAY_SIZE (obj1
) = size
;
778 OBJECT_MAX (obj1
) = id
;
780 SET_MINMAX_SET_BIT (vec
, id
, OBJECT_MIN (obj1
), OBJECT_MAX (obj1
));
784 /* Add OBJ1 to the conflicts of OBJ2 and vice versa. */
786 ira_add_conflict (ira_object_t obj1
, ira_object_t obj2
)
788 add_to_conflicts (obj1
, obj2
);
789 add_to_conflicts (obj2
, obj1
);
792 /* Clear all conflicts of OBJ. */
794 clear_conflicts (ira_object_t obj
)
796 if (OBJECT_CONFLICT_VEC_P (obj
))
798 OBJECT_NUM_CONFLICTS (obj
) = 0;
799 OBJECT_CONFLICT_VEC (obj
)[0] = NULL
;
801 else if (OBJECT_CONFLICT_ARRAY_SIZE (obj
) != 0)
805 nw
= (OBJECT_MAX (obj
) - OBJECT_MIN (obj
)) / IRA_INT_BITS
+ 1;
806 memset (OBJECT_CONFLICT_BITVEC (obj
), 0, nw
* sizeof (IRA_INT_TYPE
));
810 /* The array used to find duplications in conflict vectors of
812 static int *conflict_check
;
814 /* The value used to mark allocation presence in conflict vector of
815 the current allocno. */
816 static int curr_conflict_check_tick
;
818 /* Remove duplications in conflict vector of OBJ. */
820 compress_conflict_vec (ira_object_t obj
)
822 ira_object_t
*vec
, conflict_obj
;
825 ira_assert (OBJECT_CONFLICT_VEC_P (obj
));
826 vec
= OBJECT_CONFLICT_VEC (obj
);
827 curr_conflict_check_tick
++;
828 for (i
= j
= 0; (conflict_obj
= vec
[i
]) != NULL
; i
++)
830 int id
= OBJECT_CONFLICT_ID (conflict_obj
);
831 if (conflict_check
[id
] != curr_conflict_check_tick
)
833 conflict_check
[id
] = curr_conflict_check_tick
;
834 vec
[j
++] = conflict_obj
;
837 OBJECT_NUM_CONFLICTS (obj
) = j
;
841 /* Remove duplications in conflict vectors of all allocnos. */
843 compress_conflict_vecs (void)
846 ira_object_iterator oi
;
848 conflict_check
= (int *) ira_allocate (sizeof (int) * ira_objects_num
);
849 memset (conflict_check
, 0, sizeof (int) * ira_objects_num
);
850 curr_conflict_check_tick
= 0;
851 FOR_EACH_OBJECT (obj
, oi
)
853 if (OBJECT_CONFLICT_VEC_P (obj
))
854 compress_conflict_vec (obj
);
856 ira_free (conflict_check
);
859 /* This recursive function outputs allocno A and if it is a cap the
860 function outputs its members. */
862 ira_print_expanded_allocno (ira_allocno_t a
)
866 fprintf (ira_dump_file
, " a%d(r%d", ALLOCNO_NUM (a
), ALLOCNO_REGNO (a
));
867 if ((bb
= ALLOCNO_LOOP_TREE_NODE (a
)->bb
) != NULL
)
868 fprintf (ira_dump_file
, ",b%d", bb
->index
);
870 fprintf (ira_dump_file
, ",l%d", ALLOCNO_LOOP_TREE_NODE (a
)->loop_num
);
871 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
873 fprintf (ira_dump_file
, ":");
874 ira_print_expanded_allocno (ALLOCNO_CAP_MEMBER (a
));
876 fprintf (ira_dump_file
, ")");
879 /* Create and return the cap representing allocno A in the
882 create_cap_allocno (ira_allocno_t a
)
885 ira_loop_tree_node_t parent
;
886 enum reg_class aclass
;
888 parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
;
889 cap
= ira_create_allocno (ALLOCNO_REGNO (a
), true, parent
);
890 ALLOCNO_MODE (cap
) = ALLOCNO_MODE (a
);
891 ALLOCNO_WMODE (cap
) = ALLOCNO_WMODE (a
);
892 aclass
= ALLOCNO_CLASS (a
);
893 ira_set_allocno_class (cap
, aclass
);
894 ira_create_allocno_objects (cap
);
895 ALLOCNO_CAP_MEMBER (cap
) = a
;
896 ALLOCNO_CAP (a
) = cap
;
897 ALLOCNO_CLASS_COST (cap
) = ALLOCNO_CLASS_COST (a
);
898 ALLOCNO_MEMORY_COST (cap
) = ALLOCNO_MEMORY_COST (a
);
899 ira_allocate_and_copy_costs
900 (&ALLOCNO_HARD_REG_COSTS (cap
), aclass
, ALLOCNO_HARD_REG_COSTS (a
));
901 ira_allocate_and_copy_costs
902 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (cap
), aclass
,
903 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
));
904 ALLOCNO_BAD_SPILL_P (cap
) = ALLOCNO_BAD_SPILL_P (a
);
905 ALLOCNO_NREFS (cap
) = ALLOCNO_NREFS (a
);
906 ALLOCNO_FREQ (cap
) = ALLOCNO_FREQ (a
);
907 ALLOCNO_CALL_FREQ (cap
) = ALLOCNO_CALL_FREQ (a
);
909 merge_hard_reg_conflicts (a
, cap
, false);
911 ALLOCNO_CALLS_CROSSED_NUM (cap
) = ALLOCNO_CALLS_CROSSED_NUM (a
);
912 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (cap
) = ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
);
913 IOR_HARD_REG_SET (ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (cap
),
914 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
));
915 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
917 fprintf (ira_dump_file
, " Creating cap ");
918 ira_print_expanded_allocno (cap
);
919 fprintf (ira_dump_file
, "\n");
924 /* Create and return a live range for OBJECT with given attributes. */
926 ira_create_live_range (ira_object_t obj
, int start
, int finish
,
931 p
= live_range_pool
.allocate ();
939 /* Create a new live range for OBJECT and queue it at the head of its
942 ira_add_live_range_to_object (ira_object_t object
, int start
, int finish
)
945 p
= ira_create_live_range (object
, start
, finish
,
946 OBJECT_LIVE_RANGES (object
));
947 OBJECT_LIVE_RANGES (object
) = p
;
950 /* Copy allocno live range R and return the result. */
952 copy_live_range (live_range_t r
)
956 p
= live_range_pool
.allocate ();
961 /* Copy allocno live range list given by its head R and return the
964 ira_copy_live_range_list (live_range_t r
)
966 live_range_t p
, first
, last
;
970 for (first
= last
= NULL
; r
!= NULL
; r
= r
->next
)
972 p
= copy_live_range (r
);
982 /* Merge ranges R1 and R2 and returns the result. The function
983 maintains the order of ranges and tries to minimize number of the
986 ira_merge_live_ranges (live_range_t r1
, live_range_t r2
)
988 live_range_t first
, last
;
994 for (first
= last
= NULL
; r1
!= NULL
&& r2
!= NULL
;)
996 if (r1
->start
< r2
->start
)
998 if (r1
->start
<= r2
->finish
+ 1)
1000 /* Intersected ranges: merge r1 and r2 into r1. */
1001 r1
->start
= r2
->start
;
1002 if (r1
->finish
< r2
->finish
)
1003 r1
->finish
= r2
->finish
;
1004 live_range_t temp
= r2
;
1006 ira_finish_live_range (temp
);
1009 /* To try to merge with subsequent ranges in r1. */
1016 /* Add r1 to the result. */
1027 /* To try to merge with subsequent ranges in r2. */
1039 ira_assert (r1
->next
== NULL
);
1041 else if (r2
!= NULL
)
1047 ira_assert (r2
->next
== NULL
);
1051 ira_assert (last
->next
== NULL
);
1056 /* Return TRUE if live ranges R1 and R2 intersect. */
1058 ira_live_ranges_intersect_p (live_range_t r1
, live_range_t r2
)
1060 /* Remember the live ranges are always kept ordered. */
1061 while (r1
!= NULL
&& r2
!= NULL
)
1063 if (r1
->start
> r2
->finish
)
1065 else if (r2
->start
> r1
->finish
)
1073 /* Free allocno live range R. */
1075 ira_finish_live_range (live_range_t r
)
1077 live_range_pool
.remove (r
);
1080 /* Free list of allocno live ranges starting with R. */
1082 ira_finish_live_range_list (live_range_t r
)
1084 live_range_t next_r
;
1086 for (; r
!= NULL
; r
= next_r
)
1089 ira_finish_live_range (r
);
1093 /* Free updated register costs of allocno A. */
1095 ira_free_allocno_updated_costs (ira_allocno_t a
)
1097 enum reg_class aclass
;
1099 aclass
= ALLOCNO_CLASS (a
);
1100 if (ALLOCNO_UPDATED_HARD_REG_COSTS (a
) != NULL
)
1101 ira_free_cost_vector (ALLOCNO_UPDATED_HARD_REG_COSTS (a
), aclass
);
1102 ALLOCNO_UPDATED_HARD_REG_COSTS (a
) = NULL
;
1103 if (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) != NULL
)
1104 ira_free_cost_vector (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
),
1106 ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) = NULL
;
1109 /* Free and nullify all cost vectors allocated earlier for allocno
1112 ira_free_allocno_costs (ira_allocno_t a
)
1114 enum reg_class aclass
= ALLOCNO_CLASS (a
);
1116 ira_allocno_object_iterator oi
;
1118 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
1120 ira_finish_live_range_list (OBJECT_LIVE_RANGES (obj
));
1121 ira_object_id_map
[OBJECT_CONFLICT_ID (obj
)] = NULL
;
1122 if (OBJECT_CONFLICT_ARRAY (obj
) != NULL
)
1123 ira_free (OBJECT_CONFLICT_ARRAY (obj
));
1124 object_pool
.remove (obj
);
1127 ira_allocnos
[ALLOCNO_NUM (a
)] = NULL
;
1128 if (ALLOCNO_HARD_REG_COSTS (a
) != NULL
)
1129 ira_free_cost_vector (ALLOCNO_HARD_REG_COSTS (a
), aclass
);
1130 if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) != NULL
)
1131 ira_free_cost_vector (ALLOCNO_CONFLICT_HARD_REG_COSTS (a
), aclass
);
1132 if (ALLOCNO_UPDATED_HARD_REG_COSTS (a
) != NULL
)
1133 ira_free_cost_vector (ALLOCNO_UPDATED_HARD_REG_COSTS (a
), aclass
);
1134 if (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) != NULL
)
1135 ira_free_cost_vector (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
),
1137 ALLOCNO_HARD_REG_COSTS (a
) = NULL
;
1138 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) = NULL
;
1139 ALLOCNO_UPDATED_HARD_REG_COSTS (a
) = NULL
;
1140 ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) = NULL
;
1143 /* Free the memory allocated for allocno A. */
1145 finish_allocno (ira_allocno_t a
)
1147 ira_free_allocno_costs (a
);
1148 allocno_pool
.remove (a
);
1151 /* Free the memory allocated for all allocnos. */
1153 finish_allocnos (void)
1156 ira_allocno_iterator ai
;
1158 FOR_EACH_ALLOCNO (a
, ai
)
1160 ira_free (ira_regno_allocno_map
);
1161 ira_object_id_map_vec
.release ();
1162 allocno_vec
.release ();
1163 allocno_pool
.release ();
1164 object_pool
.release ();
1165 live_range_pool
.release ();
1170 /* Pools for allocno preferences. */
1171 static object_allocator
<ira_allocno_pref
> pref_pool ("prefs");
1173 /* Vec containing references to all created preferences. It is a
1174 container of array ira_prefs. */
1175 static vec
<ira_pref_t
> pref_vec
;
1177 /* The function initializes data concerning allocno prefs. */
1179 initiate_prefs (void)
1181 pref_vec
.create (get_max_uid ());
1186 /* Return pref for A and HARD_REGNO if any. */
1188 find_allocno_pref (ira_allocno_t a
, int hard_regno
)
1192 for (pref
= ALLOCNO_PREFS (a
); pref
!= NULL
; pref
= pref
->next_pref
)
1193 if (pref
->allocno
== a
&& pref
->hard_regno
== hard_regno
)
1198 /* Create and return pref with given attributes A, HARD_REGNO, and FREQ. */
1200 ira_create_pref (ira_allocno_t a
, int hard_regno
, int freq
)
1204 pref
= pref_pool
.allocate ();
1205 pref
->num
= ira_prefs_num
;
1207 pref
->hard_regno
= hard_regno
;
1209 pref_vec
.safe_push (pref
);
1210 ira_prefs
= pref_vec
.address ();
1211 ira_prefs_num
= pref_vec
.length ();
1215 /* Attach a pref PREF to the corresponding allocno. */
1217 add_allocno_pref_to_list (ira_pref_t pref
)
1219 ira_allocno_t a
= pref
->allocno
;
1221 pref
->next_pref
= ALLOCNO_PREFS (a
);
1222 ALLOCNO_PREFS (a
) = pref
;
1225 /* Create (or update frequency if the pref already exists) the pref of
1226 allocnos A preferring HARD_REGNO with frequency FREQ. */
1228 ira_add_allocno_pref (ira_allocno_t a
, int hard_regno
, int freq
)
1234 if ((pref
= find_allocno_pref (a
, hard_regno
)) != NULL
)
1239 pref
= ira_create_pref (a
, hard_regno
, freq
);
1240 ira_assert (a
!= NULL
);
1241 add_allocno_pref_to_list (pref
);
1244 /* Print info about PREF into file F. */
1246 print_pref (FILE *f
, ira_pref_t pref
)
1248 fprintf (f
, " pref%d:a%d(r%d)<-hr%d@%d\n", pref
->num
,
1249 ALLOCNO_NUM (pref
->allocno
), ALLOCNO_REGNO (pref
->allocno
),
1250 pref
->hard_regno
, pref
->freq
);
1253 /* Print info about PREF into stderr. */
1255 ira_debug_pref (ira_pref_t pref
)
1257 print_pref (stderr
, pref
);
1260 /* Print info about all prefs into file F. */
1262 print_prefs (FILE *f
)
1265 ira_pref_iterator pi
;
1267 FOR_EACH_PREF (pref
, pi
)
1268 print_pref (f
, pref
);
1271 /* Print info about all prefs into stderr. */
1273 ira_debug_prefs (void)
1275 print_prefs (stderr
);
1278 /* Print info about prefs involving allocno A into file F. */
1280 print_allocno_prefs (FILE *f
, ira_allocno_t a
)
1284 fprintf (f
, " a%d(r%d):", ALLOCNO_NUM (a
), ALLOCNO_REGNO (a
));
1285 for (pref
= ALLOCNO_PREFS (a
); pref
!= NULL
; pref
= pref
->next_pref
)
1286 fprintf (f
, " pref%d:hr%d@%d", pref
->num
, pref
->hard_regno
, pref
->freq
);
1290 /* Print info about prefs involving allocno A into stderr. */
1292 ira_debug_allocno_prefs (ira_allocno_t a
)
1294 print_allocno_prefs (stderr
, a
);
1297 /* The function frees memory allocated for PREF. */
1299 finish_pref (ira_pref_t pref
)
1301 ira_prefs
[pref
->num
] = NULL
;
1302 pref_pool
.remove (pref
);
1305 /* Remove PREF from the list of allocno prefs and free memory for
1308 ira_remove_pref (ira_pref_t pref
)
1310 ira_pref_t cpref
, prev
;
1312 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
1313 fprintf (ira_dump_file
, " Removing pref%d:hr%d@%d\n",
1314 pref
->num
, pref
->hard_regno
, pref
->freq
);
1315 for (prev
= NULL
, cpref
= ALLOCNO_PREFS (pref
->allocno
);
1317 prev
= cpref
, cpref
= cpref
->next_pref
)
1320 ira_assert (cpref
!= NULL
);
1322 ALLOCNO_PREFS (pref
->allocno
) = pref
->next_pref
;
1324 prev
->next_pref
= pref
->next_pref
;
1328 /* Remove all prefs of allocno A. */
1330 ira_remove_allocno_prefs (ira_allocno_t a
)
1332 ira_pref_t pref
, next_pref
;
1334 for (pref
= ALLOCNO_PREFS (a
); pref
!= NULL
; pref
= next_pref
)
1336 next_pref
= pref
->next_pref
;
1339 ALLOCNO_PREFS (a
) = NULL
;
1342 /* Free memory allocated for all prefs. */
1347 ira_pref_iterator pi
;
1349 FOR_EACH_PREF (pref
, pi
)
1351 pref_vec
.release ();
1352 pref_pool
.release ();
1357 /* Pools for copies. */
1358 static object_allocator
<ira_allocno_copy
> copy_pool ("copies");
1360 /* Vec containing references to all created copies. It is a
1361 container of array ira_copies. */
1362 static vec
<ira_copy_t
> copy_vec
;
1364 /* The function initializes data concerning allocno copies. */
1366 initiate_copies (void)
1368 copy_vec
.create (get_max_uid ());
1373 /* Return copy connecting A1 and A2 and originated from INSN of
1374 LOOP_TREE_NODE if any. */
1376 find_allocno_copy (ira_allocno_t a1
, ira_allocno_t a2
, rtx_insn
*insn
,
1377 ira_loop_tree_node_t loop_tree_node
)
1379 ira_copy_t cp
, next_cp
;
1380 ira_allocno_t another_a
;
1382 for (cp
= ALLOCNO_COPIES (a1
); cp
!= NULL
; cp
= next_cp
)
1384 if (cp
->first
== a1
)
1386 next_cp
= cp
->next_first_allocno_copy
;
1387 another_a
= cp
->second
;
1389 else if (cp
->second
== a1
)
1391 next_cp
= cp
->next_second_allocno_copy
;
1392 another_a
= cp
->first
;
1396 if (another_a
== a2
&& cp
->insn
== insn
1397 && cp
->loop_tree_node
== loop_tree_node
)
1403 /* Create and return copy with given attributes LOOP_TREE_NODE, FIRST,
1404 SECOND, FREQ, CONSTRAINT_P, and INSN. */
1406 ira_create_copy (ira_allocno_t first
, ira_allocno_t second
, int freq
,
1407 bool constraint_p
, rtx_insn
*insn
,
1408 ira_loop_tree_node_t loop_tree_node
)
1412 cp
= copy_pool
.allocate ();
1413 cp
->num
= ira_copies_num
;
1415 cp
->second
= second
;
1417 cp
->constraint_p
= constraint_p
;
1419 cp
->loop_tree_node
= loop_tree_node
;
1420 copy_vec
.safe_push (cp
);
1421 ira_copies
= copy_vec
.address ();
1422 ira_copies_num
= copy_vec
.length ();
1426 /* Attach a copy CP to allocnos involved into the copy. */
1428 add_allocno_copy_to_list (ira_copy_t cp
)
1430 ira_allocno_t first
= cp
->first
, second
= cp
->second
;
1432 cp
->prev_first_allocno_copy
= NULL
;
1433 cp
->prev_second_allocno_copy
= NULL
;
1434 cp
->next_first_allocno_copy
= ALLOCNO_COPIES (first
);
1435 if (cp
->next_first_allocno_copy
!= NULL
)
1437 if (cp
->next_first_allocno_copy
->first
== first
)
1438 cp
->next_first_allocno_copy
->prev_first_allocno_copy
= cp
;
1440 cp
->next_first_allocno_copy
->prev_second_allocno_copy
= cp
;
1442 cp
->next_second_allocno_copy
= ALLOCNO_COPIES (second
);
1443 if (cp
->next_second_allocno_copy
!= NULL
)
1445 if (cp
->next_second_allocno_copy
->second
== second
)
1446 cp
->next_second_allocno_copy
->prev_second_allocno_copy
= cp
;
1448 cp
->next_second_allocno_copy
->prev_first_allocno_copy
= cp
;
1450 ALLOCNO_COPIES (first
) = cp
;
1451 ALLOCNO_COPIES (second
) = cp
;
1454 /* Make a copy CP a canonical copy where number of the
1455 first allocno is less than the second one. */
1457 swap_allocno_copy_ends_if_necessary (ira_copy_t cp
)
1459 if (ALLOCNO_NUM (cp
->first
) <= ALLOCNO_NUM (cp
->second
))
1462 std::swap (cp
->first
, cp
->second
);
1463 std::swap (cp
->prev_first_allocno_copy
, cp
->prev_second_allocno_copy
);
1464 std::swap (cp
->next_first_allocno_copy
, cp
->next_second_allocno_copy
);
1467 /* Create (or update frequency if the copy already exists) and return
1468 the copy of allocnos FIRST and SECOND with frequency FREQ
1469 corresponding to move insn INSN (if any) and originated from
1472 ira_add_allocno_copy (ira_allocno_t first
, ira_allocno_t second
, int freq
,
1473 bool constraint_p
, rtx_insn
*insn
,
1474 ira_loop_tree_node_t loop_tree_node
)
1478 if ((cp
= find_allocno_copy (first
, second
, insn
, loop_tree_node
)) != NULL
)
1483 cp
= ira_create_copy (first
, second
, freq
, constraint_p
, insn
,
1485 ira_assert (first
!= NULL
&& second
!= NULL
);
1486 add_allocno_copy_to_list (cp
);
1487 swap_allocno_copy_ends_if_necessary (cp
);
1491 /* Print info about copy CP into file F. */
1493 print_copy (FILE *f
, ira_copy_t cp
)
1495 fprintf (f
, " cp%d:a%d(r%d)<->a%d(r%d)@%d:%s\n", cp
->num
,
1496 ALLOCNO_NUM (cp
->first
), ALLOCNO_REGNO (cp
->first
),
1497 ALLOCNO_NUM (cp
->second
), ALLOCNO_REGNO (cp
->second
), cp
->freq
,
1499 ? "move" : cp
->constraint_p
? "constraint" : "shuffle");
1503 debug (ira_allocno_copy
&ref
)
1505 print_copy (stderr
, &ref
);
1509 debug (ira_allocno_copy
*ptr
)
1514 fprintf (stderr
, "<nil>\n");
1517 /* Print info about copy CP into stderr. */
1519 ira_debug_copy (ira_copy_t cp
)
1521 print_copy (stderr
, cp
);
1524 /* Print info about all copies into file F. */
1526 print_copies (FILE *f
)
1529 ira_copy_iterator ci
;
1531 FOR_EACH_COPY (cp
, ci
)
1535 /* Print info about all copies into stderr. */
1537 ira_debug_copies (void)
1539 print_copies (stderr
);
1542 /* Print info about copies involving allocno A into file F. */
1544 print_allocno_copies (FILE *f
, ira_allocno_t a
)
1546 ira_allocno_t another_a
;
1547 ira_copy_t cp
, next_cp
;
1549 fprintf (f
, " a%d(r%d):", ALLOCNO_NUM (a
), ALLOCNO_REGNO (a
));
1550 for (cp
= ALLOCNO_COPIES (a
); cp
!= NULL
; cp
= next_cp
)
1554 next_cp
= cp
->next_first_allocno_copy
;
1555 another_a
= cp
->second
;
1557 else if (cp
->second
== a
)
1559 next_cp
= cp
->next_second_allocno_copy
;
1560 another_a
= cp
->first
;
1564 fprintf (f
, " cp%d:a%d(r%d)@%d", cp
->num
,
1565 ALLOCNO_NUM (another_a
), ALLOCNO_REGNO (another_a
), cp
->freq
);
1571 debug (ira_allocno
&ref
)
1573 print_allocno_copies (stderr
, &ref
);
1577 debug (ira_allocno
*ptr
)
1582 fprintf (stderr
, "<nil>\n");
1586 /* Print info about copies involving allocno A into stderr. */
1588 ira_debug_allocno_copies (ira_allocno_t a
)
1590 print_allocno_copies (stderr
, a
);
1593 /* The function frees memory allocated for copy CP. */
1595 finish_copy (ira_copy_t cp
)
1597 copy_pool
.remove (cp
);
1601 /* Free memory allocated for all copies. */
1603 finish_copies (void)
1606 ira_copy_iterator ci
;
1608 FOR_EACH_COPY (cp
, ci
)
1610 copy_vec
.release ();
1611 copy_pool
.release ();
1616 /* Pools for cost vectors. It is defined only for allocno classes. */
1617 static pool_allocator
*cost_vector_pool
[N_REG_CLASSES
];
1619 /* The function initiates work with hard register cost vectors. It
1620 creates allocation pool for each allocno class. */
1622 initiate_cost_vectors (void)
1625 enum reg_class aclass
;
1627 for (i
= 0; i
< ira_allocno_classes_num
; i
++)
1629 aclass
= ira_allocno_classes
[i
];
1630 cost_vector_pool
[aclass
] = new pool_allocator
1631 ("cost vectors", sizeof (int) * (ira_class_hard_regs_num
[aclass
]));
1635 /* Allocate and return a cost vector VEC for ACLASS. */
1637 ira_allocate_cost_vector (reg_class_t aclass
)
1639 return (int*) cost_vector_pool
[(int) aclass
]->allocate ();
1642 /* Free a cost vector VEC for ACLASS. */
1644 ira_free_cost_vector (int *vec
, reg_class_t aclass
)
1646 ira_assert (vec
!= NULL
);
1647 cost_vector_pool
[(int) aclass
]->remove (vec
);
1650 /* Finish work with hard register cost vectors. Release allocation
1651 pool for each allocno class. */
1653 finish_cost_vectors (void)
1656 enum reg_class aclass
;
1658 for (i
= 0; i
< ira_allocno_classes_num
; i
++)
1660 aclass
= ira_allocno_classes
[i
];
1661 delete cost_vector_pool
[aclass
];
1667 /* Compute a post-ordering of the reverse control flow of the loop body
1668 designated by the children nodes of LOOP_NODE, whose body nodes in
1669 pre-order are input as LOOP_PREORDER. Return a VEC with a post-order
1670 of the reverse loop body.
1672 For the post-order of the reverse CFG, we visit the basic blocks in
1673 LOOP_PREORDER array in the reverse order of where they appear.
1674 This is important: We do not just want to compute a post-order of
1675 the reverse CFG, we want to make a best-guess for a visiting order that
1676 minimizes the number of chain elements per allocno live range. If the
1677 blocks would be visited in a different order, we would still compute a
1678 correct post-ordering but it would be less likely that two nodes
1679 connected by an edge in the CFG are neighbours in the topsort. */
1681 static vec
<ira_loop_tree_node_t
>
1682 ira_loop_tree_body_rev_postorder (ira_loop_tree_node_t loop_node ATTRIBUTE_UNUSED
,
1683 vec
<ira_loop_tree_node_t
> loop_preorder
)
1685 vec
<ira_loop_tree_node_t
> topsort_nodes
= vNULL
;
1686 unsigned int n_loop_preorder
;
1688 n_loop_preorder
= loop_preorder
.length ();
1689 if (n_loop_preorder
!= 0)
1691 ira_loop_tree_node_t subloop_node
;
1693 auto_vec
<ira_loop_tree_node_t
> dfs_stack
;
1695 /* This is a bit of strange abuse of the BB_VISITED flag: We use
1696 the flag to mark blocks we still have to visit to add them to
1697 our post-order. Define an alias to avoid confusion. */
1698 #define BB_TO_VISIT BB_VISITED
1700 FOR_EACH_VEC_ELT (loop_preorder
, i
, subloop_node
)
1702 gcc_checking_assert (! (subloop_node
->bb
->flags
& BB_TO_VISIT
));
1703 subloop_node
->bb
->flags
|= BB_TO_VISIT
;
1706 topsort_nodes
.create (n_loop_preorder
);
1707 dfs_stack
.create (n_loop_preorder
);
1709 FOR_EACH_VEC_ELT_REVERSE (loop_preorder
, i
, subloop_node
)
1711 if (! (subloop_node
->bb
->flags
& BB_TO_VISIT
))
1714 subloop_node
->bb
->flags
&= ~BB_TO_VISIT
;
1715 dfs_stack
.quick_push (subloop_node
);
1716 while (! dfs_stack
.is_empty ())
1721 ira_loop_tree_node_t n
= dfs_stack
.last ();
1722 FOR_EACH_EDGE (e
, ei
, n
->bb
->preds
)
1724 ira_loop_tree_node_t pred_node
;
1725 basic_block pred_bb
= e
->src
;
1727 if (e
->src
== ENTRY_BLOCK_PTR_FOR_FN (cfun
))
1730 pred_node
= IRA_BB_NODE_BY_INDEX (pred_bb
->index
);
1732 && (pred_node
->bb
->flags
& BB_TO_VISIT
))
1734 pred_node
->bb
->flags
&= ~BB_TO_VISIT
;
1735 dfs_stack
.quick_push (pred_node
);
1738 if (n
== dfs_stack
.last ())
1741 topsort_nodes
.quick_push (n
);
1749 gcc_assert (topsort_nodes
.length () == n_loop_preorder
);
1750 return topsort_nodes
;
1753 /* The current loop tree node and its regno allocno map. */
1754 ira_loop_tree_node_t ira_curr_loop_tree_node
;
1755 ira_allocno_t
*ira_curr_regno_allocno_map
;
1757 /* This recursive function traverses loop tree with root LOOP_NODE
1758 calling non-null functions PREORDER_FUNC and POSTORDER_FUNC
1759 correspondingly in preorder and postorder. The function sets up
1760 IRA_CURR_LOOP_TREE_NODE and IRA_CURR_REGNO_ALLOCNO_MAP. If BB_P,
1761 basic block nodes of LOOP_NODE is also processed (before its
1764 If BB_P is set and POSTORDER_FUNC is given, the basic blocks in
1765 the loop are passed in the *reverse* post-order of the *reverse*
1766 CFG. This is only used by ira_create_allocno_live_ranges, which
1767 wants to visit basic blocks in this order to minimize the number
1768 of elements per live range chain.
1769 Note that the loop tree nodes are still visited in the normal,
1770 forward post-order of the loop tree. */
1773 ira_traverse_loop_tree (bool bb_p
, ira_loop_tree_node_t loop_node
,
1774 void (*preorder_func
) (ira_loop_tree_node_t
),
1775 void (*postorder_func
) (ira_loop_tree_node_t
))
1777 ira_loop_tree_node_t subloop_node
;
1779 ira_assert (loop_node
->bb
== NULL
);
1780 ira_curr_loop_tree_node
= loop_node
;
1781 ira_curr_regno_allocno_map
= ira_curr_loop_tree_node
->regno_allocno_map
;
1783 if (preorder_func
!= NULL
)
1784 (*preorder_func
) (loop_node
);
1788 auto_vec
<ira_loop_tree_node_t
> loop_preorder
;
1791 /* Add all nodes to the set of nodes to visit. The IRA loop tree
1792 is set up such that nodes in the loop body appear in a pre-order
1793 of their place in the CFG. */
1794 for (subloop_node
= loop_node
->children
;
1795 subloop_node
!= NULL
;
1796 subloop_node
= subloop_node
->next
)
1797 if (subloop_node
->bb
!= NULL
)
1798 loop_preorder
.safe_push (subloop_node
);
1800 if (preorder_func
!= NULL
)
1801 FOR_EACH_VEC_ELT (loop_preorder
, i
, subloop_node
)
1802 (*preorder_func
) (subloop_node
);
1804 if (postorder_func
!= NULL
)
1806 vec
<ira_loop_tree_node_t
> loop_rev_postorder
=
1807 ira_loop_tree_body_rev_postorder (loop_node
, loop_preorder
);
1808 FOR_EACH_VEC_ELT_REVERSE (loop_rev_postorder
, i
, subloop_node
)
1809 (*postorder_func
) (subloop_node
);
1810 loop_rev_postorder
.release ();
1814 for (subloop_node
= loop_node
->subloops
;
1815 subloop_node
!= NULL
;
1816 subloop_node
= subloop_node
->subloop_next
)
1818 ira_assert (subloop_node
->bb
== NULL
);
1819 ira_traverse_loop_tree (bb_p
, subloop_node
,
1820 preorder_func
, postorder_func
);
1823 ira_curr_loop_tree_node
= loop_node
;
1824 ira_curr_regno_allocno_map
= ira_curr_loop_tree_node
->regno_allocno_map
;
1826 if (postorder_func
!= NULL
)
1827 (*postorder_func
) (loop_node
);
1832 /* The basic block currently being processed. */
1833 static basic_block curr_bb
;
1835 /* This recursive function creates allocnos corresponding to
1836 pseudo-registers containing in X. True OUTPUT_P means that X is
1837 an lvalue. PARENT corresponds to the parent expression of X. */
1839 create_insn_allocnos (rtx x
, rtx outer
, bool output_p
)
1843 enum rtx_code code
= GET_CODE (x
);
1849 if ((regno
= REGNO (x
)) >= FIRST_PSEUDO_REGISTER
)
1853 if ((a
= ira_curr_regno_allocno_map
[regno
]) == NULL
)
1855 a
= ira_create_allocno (regno
, false, ira_curr_loop_tree_node
);
1856 if (outer
!= NULL
&& GET_CODE (outer
) == SUBREG
)
1858 machine_mode wmode
= GET_MODE (outer
);
1859 if (GET_MODE_SIZE (wmode
) > GET_MODE_SIZE (ALLOCNO_WMODE (a
)))
1860 ALLOCNO_WMODE (a
) = wmode
;
1864 ALLOCNO_NREFS (a
)++;
1865 ALLOCNO_FREQ (a
) += REG_FREQ_FROM_BB (curr_bb
);
1867 bitmap_set_bit (ira_curr_loop_tree_node
->modified_regnos
, regno
);
1871 else if (code
== SET
)
1873 create_insn_allocnos (SET_DEST (x
), NULL
, true);
1874 create_insn_allocnos (SET_SRC (x
), NULL
, false);
1877 else if (code
== CLOBBER
)
1879 create_insn_allocnos (XEXP (x
, 0), NULL
, true);
1882 else if (code
== MEM
)
1884 create_insn_allocnos (XEXP (x
, 0), NULL
, false);
1887 else if (code
== PRE_DEC
|| code
== POST_DEC
|| code
== PRE_INC
||
1888 code
== POST_INC
|| code
== POST_MODIFY
|| code
== PRE_MODIFY
)
1890 create_insn_allocnos (XEXP (x
, 0), NULL
, true);
1891 create_insn_allocnos (XEXP (x
, 0), NULL
, false);
1895 fmt
= GET_RTX_FORMAT (code
);
1896 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1899 create_insn_allocnos (XEXP (x
, i
), x
, output_p
);
1900 else if (fmt
[i
] == 'E')
1901 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1902 create_insn_allocnos (XVECEXP (x
, i
, j
), x
, output_p
);
1906 /* Create allocnos corresponding to pseudo-registers living in the
1907 basic block represented by the corresponding loop tree node
1910 create_bb_allocnos (ira_loop_tree_node_t bb_node
)
1917 curr_bb
= bb
= bb_node
->bb
;
1918 ira_assert (bb
!= NULL
);
1919 FOR_BB_INSNS_REVERSE (bb
, insn
)
1920 if (NONDEBUG_INSN_P (insn
))
1921 create_insn_allocnos (PATTERN (insn
), NULL
, false);
1922 /* It might be a allocno living through from one subloop to
1924 EXECUTE_IF_SET_IN_REG_SET (df_get_live_in (bb
), FIRST_PSEUDO_REGISTER
, i
, bi
)
1925 if (ira_curr_regno_allocno_map
[i
] == NULL
)
1926 ira_create_allocno (i
, false, ira_curr_loop_tree_node
);
1929 /* Create allocnos corresponding to pseudo-registers living on edge E
1930 (a loop entry or exit). Also mark the allocnos as living on the
1933 create_loop_allocnos (edge e
)
1936 bitmap live_in_regs
, border_allocnos
;
1938 ira_loop_tree_node_t parent
;
1940 live_in_regs
= df_get_live_in (e
->dest
);
1941 border_allocnos
= ira_curr_loop_tree_node
->border_allocnos
;
1942 EXECUTE_IF_SET_IN_REG_SET (df_get_live_out (e
->src
),
1943 FIRST_PSEUDO_REGISTER
, i
, bi
)
1944 if (bitmap_bit_p (live_in_regs
, i
))
1946 if (ira_curr_regno_allocno_map
[i
] == NULL
)
1948 /* The order of creations is important for right
1949 ira_regno_allocno_map. */
1950 if ((parent
= ira_curr_loop_tree_node
->parent
) != NULL
1951 && parent
->regno_allocno_map
[i
] == NULL
)
1952 ira_create_allocno (i
, false, parent
);
1953 ira_create_allocno (i
, false, ira_curr_loop_tree_node
);
1955 bitmap_set_bit (border_allocnos
,
1956 ALLOCNO_NUM (ira_curr_regno_allocno_map
[i
]));
1960 /* Create allocnos corresponding to pseudo-registers living in loop
1961 represented by the corresponding loop tree node LOOP_NODE. This
1962 function is called by ira_traverse_loop_tree. */
1964 create_loop_tree_node_allocnos (ira_loop_tree_node_t loop_node
)
1966 if (loop_node
->bb
!= NULL
)
1967 create_bb_allocnos (loop_node
);
1968 else if (loop_node
!= ira_loop_tree_root
)
1975 ira_assert (current_loops
!= NULL
);
1976 FOR_EACH_EDGE (e
, ei
, loop_node
->loop
->header
->preds
)
1977 if (e
->src
!= loop_node
->loop
->latch
)
1978 create_loop_allocnos (e
);
1980 edges
= get_loop_exit_edges (loop_node
->loop
);
1981 FOR_EACH_VEC_ELT (edges
, i
, e
)
1982 create_loop_allocnos (e
);
1987 /* Propagate information about allocnos modified inside the loop given
1988 by its LOOP_TREE_NODE to its parent. */
1990 propagate_modified_regnos (ira_loop_tree_node_t loop_tree_node
)
1992 if (loop_tree_node
== ira_loop_tree_root
)
1994 ira_assert (loop_tree_node
->bb
== NULL
);
1995 bitmap_ior_into (loop_tree_node
->parent
->modified_regnos
,
1996 loop_tree_node
->modified_regnos
);
1999 /* Propagate new info about allocno A (see comments about accumulated
2000 info in allocno definition) to the corresponding allocno on upper
2001 loop tree level. So allocnos on upper levels accumulate
2002 information about the corresponding allocnos in nested regions.
2003 The new info means allocno info finally calculated in this
2006 propagate_allocno_info (void)
2009 ira_allocno_t a
, parent_a
;
2010 ira_loop_tree_node_t parent
;
2011 enum reg_class aclass
;
2013 if (flag_ira_region
!= IRA_REGION_ALL
2014 && flag_ira_region
!= IRA_REGION_MIXED
)
2016 for (i
= max_reg_num () - 1; i
>= FIRST_PSEUDO_REGISTER
; i
--)
2017 for (a
= ira_regno_allocno_map
[i
];
2019 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
2020 if ((parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
) != NULL
2021 && (parent_a
= parent
->regno_allocno_map
[i
]) != NULL
2022 /* There are no caps yet at this point. So use
2023 border_allocnos to find allocnos for the propagation. */
2024 && bitmap_bit_p (ALLOCNO_LOOP_TREE_NODE (a
)->border_allocnos
,
2027 if (! ALLOCNO_BAD_SPILL_P (a
))
2028 ALLOCNO_BAD_SPILL_P (parent_a
) = false;
2029 ALLOCNO_NREFS (parent_a
) += ALLOCNO_NREFS (a
);
2030 ALLOCNO_FREQ (parent_a
) += ALLOCNO_FREQ (a
);
2031 ALLOCNO_CALL_FREQ (parent_a
) += ALLOCNO_CALL_FREQ (a
);
2032 merge_hard_reg_conflicts (a
, parent_a
, true);
2033 ALLOCNO_CALLS_CROSSED_NUM (parent_a
)
2034 += ALLOCNO_CALLS_CROSSED_NUM (a
);
2035 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a
)
2036 += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
);
2037 IOR_HARD_REG_SET (ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (parent_a
),
2038 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
));
2039 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a
)
2040 += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
);
2041 aclass
= ALLOCNO_CLASS (a
);
2042 ira_assert (aclass
== ALLOCNO_CLASS (parent_a
));
2043 ira_allocate_and_accumulate_costs
2044 (&ALLOCNO_HARD_REG_COSTS (parent_a
), aclass
,
2045 ALLOCNO_HARD_REG_COSTS (a
));
2046 ira_allocate_and_accumulate_costs
2047 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a
),
2049 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
));
2050 ALLOCNO_CLASS_COST (parent_a
)
2051 += ALLOCNO_CLASS_COST (a
);
2052 ALLOCNO_MEMORY_COST (parent_a
) += ALLOCNO_MEMORY_COST (a
);
2056 /* Create allocnos corresponding to pseudo-registers in the current
2057 function. Traverse the loop tree for this. */
2059 create_allocnos (void)
2061 /* We need to process BB first to correctly link allocnos by member
2062 next_regno_allocno. */
2063 ira_traverse_loop_tree (true, ira_loop_tree_root
,
2064 create_loop_tree_node_allocnos
, NULL
);
2066 ira_traverse_loop_tree (false, ira_loop_tree_root
, NULL
,
2067 propagate_modified_regnos
);
2072 /* The page contains function to remove some regions from a separate
2073 register allocation. We remove regions whose separate allocation
2074 will hardly improve the result. As a result we speed up regional
2075 register allocation. */
2077 /* The function changes the object in range list given by R to OBJ. */
2079 change_object_in_range_list (live_range_t r
, ira_object_t obj
)
2081 for (; r
!= NULL
; r
= r
->next
)
2085 /* Move all live ranges associated with allocno FROM to allocno TO. */
2087 move_allocno_live_ranges (ira_allocno_t from
, ira_allocno_t to
)
2090 int n
= ALLOCNO_NUM_OBJECTS (from
);
2092 gcc_assert (n
== ALLOCNO_NUM_OBJECTS (to
));
2094 for (i
= 0; i
< n
; i
++)
2096 ira_object_t from_obj
= ALLOCNO_OBJECT (from
, i
);
2097 ira_object_t to_obj
= ALLOCNO_OBJECT (to
, i
);
2098 live_range_t lr
= OBJECT_LIVE_RANGES (from_obj
);
2100 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
2102 fprintf (ira_dump_file
,
2103 " Moving ranges of a%dr%d to a%dr%d: ",
2104 ALLOCNO_NUM (from
), ALLOCNO_REGNO (from
),
2105 ALLOCNO_NUM (to
), ALLOCNO_REGNO (to
));
2106 ira_print_live_range_list (ira_dump_file
, lr
);
2108 change_object_in_range_list (lr
, to_obj
);
2109 OBJECT_LIVE_RANGES (to_obj
)
2110 = ira_merge_live_ranges (lr
, OBJECT_LIVE_RANGES (to_obj
));
2111 OBJECT_LIVE_RANGES (from_obj
) = NULL
;
2116 copy_allocno_live_ranges (ira_allocno_t from
, ira_allocno_t to
)
2119 int n
= ALLOCNO_NUM_OBJECTS (from
);
2121 gcc_assert (n
== ALLOCNO_NUM_OBJECTS (to
));
2123 for (i
= 0; i
< n
; i
++)
2125 ira_object_t from_obj
= ALLOCNO_OBJECT (from
, i
);
2126 ira_object_t to_obj
= ALLOCNO_OBJECT (to
, i
);
2127 live_range_t lr
= OBJECT_LIVE_RANGES (from_obj
);
2129 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
2131 fprintf (ira_dump_file
, " Copying ranges of a%dr%d to a%dr%d: ",
2132 ALLOCNO_NUM (from
), ALLOCNO_REGNO (from
),
2133 ALLOCNO_NUM (to
), ALLOCNO_REGNO (to
));
2134 ira_print_live_range_list (ira_dump_file
, lr
);
2136 lr
= ira_copy_live_range_list (lr
);
2137 change_object_in_range_list (lr
, to_obj
);
2138 OBJECT_LIVE_RANGES (to_obj
)
2139 = ira_merge_live_ranges (lr
, OBJECT_LIVE_RANGES (to_obj
));
2143 /* Return TRUE if NODE represents a loop with low register
2146 low_pressure_loop_node_p (ira_loop_tree_node_t node
)
2149 enum reg_class pclass
;
2151 if (node
->bb
!= NULL
)
2154 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
2156 pclass
= ira_pressure_classes
[i
];
2157 if (node
->reg_pressure
[pclass
] > ira_class_hard_regs_num
[pclass
]
2158 && ira_class_hard_regs_num
[pclass
] > 1)
2165 /* Return TRUE if LOOP has a complex enter or exit edge. We don't
2166 form a region from such loop if the target use stack register
2167 because reg-stack.c can not deal with such edges. */
2169 loop_with_complex_edge_p (struct loop
*loop
)
2177 FOR_EACH_EDGE (e
, ei
, loop
->header
->preds
)
2178 if (e
->flags
& EDGE_EH
)
2180 edges
= get_loop_exit_edges (loop
);
2182 FOR_EACH_VEC_ELT (edges
, i
, e
)
2183 if (e
->flags
& EDGE_COMPLEX
)
2193 /* Sort loops for marking them for removal. We put already marked
2194 loops first, then less frequent loops next, and then outer loops
2197 loop_compare_func (const void *v1p
, const void *v2p
)
2200 ira_loop_tree_node_t l1
= *(const ira_loop_tree_node_t
*) v1p
;
2201 ira_loop_tree_node_t l2
= *(const ira_loop_tree_node_t
*) v2p
;
2203 ira_assert (l1
->parent
!= NULL
&& l2
->parent
!= NULL
);
2204 if (l1
->to_remove_p
&& ! l2
->to_remove_p
)
2206 if (! l1
->to_remove_p
&& l2
->to_remove_p
)
2208 if ((diff
= l1
->loop
->header
->frequency
- l2
->loop
->header
->frequency
) != 0)
2210 if ((diff
= (int) loop_depth (l1
->loop
) - (int) loop_depth (l2
->loop
)) != 0)
2212 /* Make sorting stable. */
2213 return l1
->loop_num
- l2
->loop_num
;
2216 /* Mark loops which should be removed from regional allocation. We
2217 remove a loop with low register pressure inside another loop with
2218 register pressure. In this case a separate allocation of the loop
2219 hardly helps (for irregular register file architecture it could
2220 help by choosing a better hard register in the loop but we prefer
2221 faster allocation even in this case). We also remove cheap loops
2222 if there are more than IRA_MAX_LOOPS_NUM of them. Loop with EH
2223 exit or enter edges are removed too because the allocation might
2224 require put pseudo moves on the EH edges (we could still do this
2225 for pseudos with caller saved hard registers in some cases but it
2226 is impossible to say here or during top-down allocation pass what
2227 hard register the pseudos get finally). */
2229 mark_loops_for_removal (void)
2232 ira_loop_tree_node_t
*sorted_loops
;
2235 ira_assert (current_loops
!= NULL
);
2237 = (ira_loop_tree_node_t
*) ira_allocate (sizeof (ira_loop_tree_node_t
)
2238 * number_of_loops (cfun
));
2239 for (n
= i
= 0; vec_safe_iterate (get_loops (cfun
), i
, &loop
); i
++)
2240 if (ira_loop_nodes
[i
].regno_allocno_map
!= NULL
)
2242 if (ira_loop_nodes
[i
].parent
== NULL
)
2244 /* Don't remove the root. */
2245 ira_loop_nodes
[i
].to_remove_p
= false;
2248 sorted_loops
[n
++] = &ira_loop_nodes
[i
];
2249 ira_loop_nodes
[i
].to_remove_p
2250 = ((low_pressure_loop_node_p (ira_loop_nodes
[i
].parent
)
2251 && low_pressure_loop_node_p (&ira_loop_nodes
[i
]))
2253 || loop_with_complex_edge_p (ira_loop_nodes
[i
].loop
)
2257 qsort (sorted_loops
, n
, sizeof (ira_loop_tree_node_t
), loop_compare_func
);
2258 for (i
= 0; n
- i
+ 1 > IRA_MAX_LOOPS_NUM
; i
++)
2260 sorted_loops
[i
]->to_remove_p
= true;
2261 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
2264 " Mark loop %d (header %d, freq %d, depth %d) for removal (%s)\n",
2265 sorted_loops
[i
]->loop_num
, sorted_loops
[i
]->loop
->header
->index
,
2266 sorted_loops
[i
]->loop
->header
->frequency
,
2267 loop_depth (sorted_loops
[i
]->loop
),
2268 low_pressure_loop_node_p (sorted_loops
[i
]->parent
)
2269 && low_pressure_loop_node_p (sorted_loops
[i
])
2270 ? "low pressure" : "cheap loop");
2272 ira_free (sorted_loops
);
2275 /* Mark all loops but root for removing. */
2277 mark_all_loops_for_removal (void)
2282 ira_assert (current_loops
!= NULL
);
2283 FOR_EACH_VEC_SAFE_ELT (get_loops (cfun
), i
, loop
)
2284 if (ira_loop_nodes
[i
].regno_allocno_map
!= NULL
)
2286 if (ira_loop_nodes
[i
].parent
== NULL
)
2288 /* Don't remove the root. */
2289 ira_loop_nodes
[i
].to_remove_p
= false;
2292 ira_loop_nodes
[i
].to_remove_p
= true;
2293 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
2296 " Mark loop %d (header %d, freq %d, depth %d) for removal\n",
2297 ira_loop_nodes
[i
].loop_num
,
2298 ira_loop_nodes
[i
].loop
->header
->index
,
2299 ira_loop_nodes
[i
].loop
->header
->frequency
,
2300 loop_depth (ira_loop_nodes
[i
].loop
));
2304 /* Definition of vector of loop tree nodes. */
2306 /* Vec containing references to all removed loop tree nodes. */
2307 static vec
<ira_loop_tree_node_t
> removed_loop_vec
;
2309 /* Vec containing references to all children of loop tree nodes. */
2310 static vec
<ira_loop_tree_node_t
> children_vec
;
2312 /* Remove subregions of NODE if their separate allocation will not
2313 improve the result. */
2315 remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_node_t node
)
2319 ira_loop_tree_node_t subnode
;
2321 remove_p
= node
->to_remove_p
;
2323 children_vec
.safe_push (node
);
2324 start
= children_vec
.length ();
2325 for (subnode
= node
->children
; subnode
!= NULL
; subnode
= subnode
->next
)
2326 if (subnode
->bb
== NULL
)
2327 remove_uneccesary_loop_nodes_from_loop_tree (subnode
);
2329 children_vec
.safe_push (subnode
);
2330 node
->children
= node
->subloops
= NULL
;
2333 removed_loop_vec
.safe_push (node
);
2336 while (children_vec
.length () > start
)
2338 subnode
= children_vec
.pop ();
2339 subnode
->parent
= node
;
2340 subnode
->next
= node
->children
;
2341 node
->children
= subnode
;
2342 if (subnode
->bb
== NULL
)
2344 subnode
->subloop_next
= node
->subloops
;
2345 node
->subloops
= subnode
;
2350 /* Return TRUE if NODE is inside PARENT. */
2352 loop_is_inside_p (ira_loop_tree_node_t node
, ira_loop_tree_node_t parent
)
2354 for (node
= node
->parent
; node
!= NULL
; node
= node
->parent
)
2360 /* Sort allocnos according to their order in regno allocno list. */
2362 regno_allocno_order_compare_func (const void *v1p
, const void *v2p
)
2364 ira_allocno_t a1
= *(const ira_allocno_t
*) v1p
;
2365 ira_allocno_t a2
= *(const ira_allocno_t
*) v2p
;
2366 ira_loop_tree_node_t n1
= ALLOCNO_LOOP_TREE_NODE (a1
);
2367 ira_loop_tree_node_t n2
= ALLOCNO_LOOP_TREE_NODE (a2
);
2369 if (loop_is_inside_p (n1
, n2
))
2371 else if (loop_is_inside_p (n2
, n1
))
2373 /* If allocnos are equally good, sort by allocno numbers, so that
2374 the results of qsort leave nothing to chance. We put allocnos
2375 with higher number first in the list because it is the original
2376 order for allocnos from loops on the same levels. */
2377 return ALLOCNO_NUM (a2
) - ALLOCNO_NUM (a1
);
2380 /* This array is used to sort allocnos to restore allocno order in
2381 the regno allocno list. */
2382 static ira_allocno_t
*regno_allocnos
;
2384 /* Restore allocno order for REGNO in the regno allocno list. */
2386 ira_rebuild_regno_allocno_list (int regno
)
2391 for (n
= 0, a
= ira_regno_allocno_map
[regno
];
2393 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
2394 regno_allocnos
[n
++] = a
;
2396 qsort (regno_allocnos
, n
, sizeof (ira_allocno_t
),
2397 regno_allocno_order_compare_func
);
2398 for (i
= 1; i
< n
; i
++)
2399 ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos
[i
- 1]) = regno_allocnos
[i
];
2400 ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos
[n
- 1]) = NULL
;
2401 ira_regno_allocno_map
[regno
] = regno_allocnos
[0];
2402 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
2403 fprintf (ira_dump_file
, " Rebuilding regno allocno list for %d\n", regno
);
2406 /* Propagate info from allocno FROM_A to allocno A. */
2408 propagate_some_info_from_allocno (ira_allocno_t a
, ira_allocno_t from_a
)
2410 enum reg_class aclass
;
2412 merge_hard_reg_conflicts (from_a
, a
, false);
2413 ALLOCNO_NREFS (a
) += ALLOCNO_NREFS (from_a
);
2414 ALLOCNO_FREQ (a
) += ALLOCNO_FREQ (from_a
);
2415 ALLOCNO_CALL_FREQ (a
) += ALLOCNO_CALL_FREQ (from_a
);
2416 ALLOCNO_CALLS_CROSSED_NUM (a
) += ALLOCNO_CALLS_CROSSED_NUM (from_a
);
2417 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
)
2418 += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (from_a
);
2419 IOR_HARD_REG_SET (ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
),
2420 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (from_a
));
2422 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
)
2423 += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (from_a
);
2424 if (! ALLOCNO_BAD_SPILL_P (from_a
))
2425 ALLOCNO_BAD_SPILL_P (a
) = false;
2426 aclass
= ALLOCNO_CLASS (from_a
);
2427 ira_assert (aclass
== ALLOCNO_CLASS (a
));
2428 ira_allocate_and_accumulate_costs (&ALLOCNO_HARD_REG_COSTS (a
), aclass
,
2429 ALLOCNO_HARD_REG_COSTS (from_a
));
2430 ira_allocate_and_accumulate_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a
),
2432 ALLOCNO_CONFLICT_HARD_REG_COSTS (from_a
));
2433 ALLOCNO_CLASS_COST (a
) += ALLOCNO_CLASS_COST (from_a
);
2434 ALLOCNO_MEMORY_COST (a
) += ALLOCNO_MEMORY_COST (from_a
);
2437 /* Remove allocnos from loops removed from the allocation
2440 remove_unnecessary_allocnos (void)
2443 bool merged_p
, rebuild_p
;
2444 ira_allocno_t a
, prev_a
, next_a
, parent_a
;
2445 ira_loop_tree_node_t a_node
, parent
;
2448 regno_allocnos
= NULL
;
2449 for (regno
= max_reg_num () - 1; regno
>= FIRST_PSEUDO_REGISTER
; regno
--)
2452 for (prev_a
= NULL
, a
= ira_regno_allocno_map
[regno
];
2456 next_a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
);
2457 a_node
= ALLOCNO_LOOP_TREE_NODE (a
);
2458 if (! a_node
->to_remove_p
)
2462 for (parent
= a_node
->parent
;
2463 (parent_a
= parent
->regno_allocno_map
[regno
]) == NULL
2464 && parent
->to_remove_p
;
2465 parent
= parent
->parent
)
2467 if (parent_a
== NULL
)
2469 /* There are no allocnos with the same regno in
2470 upper region -- just move the allocno to the
2473 ALLOCNO_LOOP_TREE_NODE (a
) = parent
;
2474 parent
->regno_allocno_map
[regno
] = a
;
2475 bitmap_set_bit (parent
->all_allocnos
, ALLOCNO_NUM (a
));
2480 /* Remove the allocno and update info of allocno in
2481 the upper region. */
2483 ira_regno_allocno_map
[regno
] = next_a
;
2485 ALLOCNO_NEXT_REGNO_ALLOCNO (prev_a
) = next_a
;
2486 move_allocno_live_ranges (a
, parent_a
);
2488 propagate_some_info_from_allocno (parent_a
, a
);
2489 /* Remove it from the corresponding regno allocno
2490 map to avoid info propagation of subsequent
2491 allocno into this already removed allocno. */
2492 a_node
->regno_allocno_map
[regno
] = NULL
;
2493 ira_remove_allocno_prefs (a
);
2499 /* We need to restore the order in regno allocno list. */
2501 if (regno_allocnos
== NULL
)
2503 = (ira_allocno_t
*) ira_allocate (sizeof (ira_allocno_t
)
2504 * ira_allocnos_num
);
2505 ira_rebuild_regno_allocno_list (regno
);
2509 ira_rebuild_start_finish_chains ();
2510 if (regno_allocnos
!= NULL
)
2511 ira_free (regno_allocnos
);
2514 /* Remove allocnos from all loops but the root. */
2516 remove_low_level_allocnos (void)
2519 bool merged_p
, propagate_p
;
2520 ira_allocno_t a
, top_a
;
2521 ira_loop_tree_node_t a_node
, parent
;
2522 ira_allocno_iterator ai
;
2525 FOR_EACH_ALLOCNO (a
, ai
)
2527 a_node
= ALLOCNO_LOOP_TREE_NODE (a
);
2528 if (a_node
== ira_loop_tree_root
|| ALLOCNO_CAP_MEMBER (a
) != NULL
)
2530 regno
= ALLOCNO_REGNO (a
);
2531 if ((top_a
= ira_loop_tree_root
->regno_allocno_map
[regno
]) == NULL
)
2533 ALLOCNO_LOOP_TREE_NODE (a
) = ira_loop_tree_root
;
2534 ira_loop_tree_root
->regno_allocno_map
[regno
] = a
;
2537 propagate_p
= a_node
->parent
->regno_allocno_map
[regno
] == NULL
;
2538 /* Remove the allocno and update info of allocno in the upper
2540 move_allocno_live_ranges (a
, top_a
);
2543 propagate_some_info_from_allocno (top_a
, a
);
2545 FOR_EACH_ALLOCNO (a
, ai
)
2547 a_node
= ALLOCNO_LOOP_TREE_NODE (a
);
2548 if (a_node
== ira_loop_tree_root
)
2550 parent
= a_node
->parent
;
2551 regno
= ALLOCNO_REGNO (a
);
2552 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
2553 ira_assert (ALLOCNO_CAP (a
) != NULL
);
2554 else if (ALLOCNO_CAP (a
) == NULL
)
2555 ira_assert (parent
->regno_allocno_map
[regno
] != NULL
);
2557 FOR_EACH_ALLOCNO (a
, ai
)
2559 regno
= ALLOCNO_REGNO (a
);
2560 if (ira_loop_tree_root
->regno_allocno_map
[regno
] == a
)
2563 ira_allocno_object_iterator oi
;
2565 ira_regno_allocno_map
[regno
] = a
;
2566 ALLOCNO_NEXT_REGNO_ALLOCNO (a
) = NULL
;
2567 ALLOCNO_CAP_MEMBER (a
) = NULL
;
2568 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
2569 COPY_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj
),
2570 OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
));
2572 if (ALLOCNO_TOTAL_NO_STACK_REG_P (a
))
2573 ALLOCNO_NO_STACK_REG_P (a
) = true;
2578 ira_remove_allocno_prefs (a
);
2583 ira_rebuild_start_finish_chains ();
2586 /* Remove loops from consideration. We remove all loops except for
2587 root if ALL_P or loops for which a separate allocation will not
2588 improve the result. We have to do this after allocno creation and
2589 their costs and allocno class evaluation because only after that
2590 the register pressure can be known and is calculated. */
2592 remove_unnecessary_regions (bool all_p
)
2594 if (current_loops
== NULL
)
2597 mark_all_loops_for_removal ();
2599 mark_loops_for_removal ();
2600 children_vec
.create (last_basic_block_for_fn (cfun
)
2601 + number_of_loops (cfun
));
2602 removed_loop_vec
.create (last_basic_block_for_fn (cfun
)
2603 + number_of_loops (cfun
));
2604 remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_root
);
2605 children_vec
.release ();
2607 remove_low_level_allocnos ();
2609 remove_unnecessary_allocnos ();
2610 while (removed_loop_vec
.length () > 0)
2611 finish_loop_tree_node (removed_loop_vec
.pop ());
2612 removed_loop_vec
.release ();
2617 /* At this point true value of allocno attribute bad_spill_p means
2618 that there is an insn where allocno occurs and where the allocno
2619 can not be used as memory. The function updates the attribute, now
2620 it can be true only for allocnos which can not be used as memory in
2621 an insn and in whose live ranges there is other allocno deaths.
2622 Spilling allocnos with true value will not improve the code because
2623 it will not make other allocnos colorable and additional reloads
2624 for the corresponding pseudo will be generated in reload pass for
2625 each insn it occurs.
2627 This is a trick mentioned in one classic article of Chaitin etc
2628 which is frequently omitted in other implementations of RA based on
2631 update_bad_spill_attribute (void)
2635 ira_allocno_iterator ai
;
2636 ira_allocno_object_iterator aoi
;
2639 enum reg_class aclass
;
2640 bitmap_head dead_points
[N_REG_CLASSES
];
2642 for (i
= 0; i
< ira_allocno_classes_num
; i
++)
2644 aclass
= ira_allocno_classes
[i
];
2645 bitmap_initialize (&dead_points
[aclass
], ®_obstack
);
2647 FOR_EACH_ALLOCNO (a
, ai
)
2649 aclass
= ALLOCNO_CLASS (a
);
2650 if (aclass
== NO_REGS
)
2652 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, aoi
)
2653 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
2654 bitmap_set_bit (&dead_points
[aclass
], r
->finish
);
2656 FOR_EACH_ALLOCNO (a
, ai
)
2658 aclass
= ALLOCNO_CLASS (a
);
2659 if (aclass
== NO_REGS
)
2661 if (! ALLOCNO_BAD_SPILL_P (a
))
2663 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, aoi
)
2665 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
2667 for (i
= r
->start
+ 1; i
< r
->finish
; i
++)
2668 if (bitmap_bit_p (&dead_points
[aclass
], i
))
2675 ALLOCNO_BAD_SPILL_P (a
) = false;
2680 for (i
= 0; i
< ira_allocno_classes_num
; i
++)
2682 aclass
= ira_allocno_classes
[i
];
2683 bitmap_clear (&dead_points
[aclass
]);
2689 /* Set up minimal and maximal live range points for allocnos. */
2691 setup_min_max_allocno_live_range_point (void)
2694 ira_allocno_t a
, parent_a
, cap
;
2695 ira_allocno_iterator ai
;
2696 #ifdef ENABLE_IRA_CHECKING
2697 ira_object_iterator oi
;
2701 ira_loop_tree_node_t parent
;
2703 FOR_EACH_ALLOCNO (a
, ai
)
2705 int n
= ALLOCNO_NUM_OBJECTS (a
);
2707 for (i
= 0; i
< n
; i
++)
2709 ira_object_t obj
= ALLOCNO_OBJECT (a
, i
);
2710 r
= OBJECT_LIVE_RANGES (obj
);
2713 OBJECT_MAX (obj
) = r
->finish
;
2714 for (; r
->next
!= NULL
; r
= r
->next
)
2716 OBJECT_MIN (obj
) = r
->start
;
2719 for (i
= max_reg_num () - 1; i
>= FIRST_PSEUDO_REGISTER
; i
--)
2720 for (a
= ira_regno_allocno_map
[i
];
2722 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
2725 int n
= ALLOCNO_NUM_OBJECTS (a
);
2727 for (j
= 0; j
< n
; j
++)
2729 ira_object_t obj
= ALLOCNO_OBJECT (a
, j
);
2730 ira_object_t parent_obj
;
2732 if (OBJECT_MAX (obj
) < 0)
2734 ira_assert (ALLOCNO_CAP_MEMBER (a
) == NULL
);
2735 /* Accumulation of range info. */
2736 if (ALLOCNO_CAP (a
) != NULL
)
2738 for (cap
= ALLOCNO_CAP (a
); cap
!= NULL
; cap
= ALLOCNO_CAP (cap
))
2740 ira_object_t cap_obj
= ALLOCNO_OBJECT (cap
, j
);
2741 if (OBJECT_MAX (cap_obj
) < OBJECT_MAX (obj
))
2742 OBJECT_MAX (cap_obj
) = OBJECT_MAX (obj
);
2743 if (OBJECT_MIN (cap_obj
) > OBJECT_MIN (obj
))
2744 OBJECT_MIN (cap_obj
) = OBJECT_MIN (obj
);
2748 if ((parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
) == NULL
)
2750 parent_a
= parent
->regno_allocno_map
[i
];
2751 parent_obj
= ALLOCNO_OBJECT (parent_a
, j
);
2752 if (OBJECT_MAX (parent_obj
) < OBJECT_MAX (obj
))
2753 OBJECT_MAX (parent_obj
) = OBJECT_MAX (obj
);
2754 if (OBJECT_MIN (parent_obj
) > OBJECT_MIN (obj
))
2755 OBJECT_MIN (parent_obj
) = OBJECT_MIN (obj
);
2758 #ifdef ENABLE_IRA_CHECKING
2759 FOR_EACH_OBJECT (obj
, oi
)
2761 if ((0 <= OBJECT_MIN (obj
) && OBJECT_MIN (obj
) <= ira_max_point
)
2762 && (0 <= OBJECT_MAX (obj
) && OBJECT_MAX (obj
) <= ira_max_point
))
2769 /* Sort allocnos according to their live ranges. Allocnos with
2770 smaller allocno class are put first unless we use priority
2771 coloring. Allocnos with the same class are ordered according
2772 their start (min). Allocnos with the same start are ordered
2773 according their finish (max). */
2775 object_range_compare_func (const void *v1p
, const void *v2p
)
2778 ira_object_t obj1
= *(const ira_object_t
*) v1p
;
2779 ira_object_t obj2
= *(const ira_object_t
*) v2p
;
2780 ira_allocno_t a1
= OBJECT_ALLOCNO (obj1
);
2781 ira_allocno_t a2
= OBJECT_ALLOCNO (obj2
);
2783 if ((diff
= OBJECT_MIN (obj1
) - OBJECT_MIN (obj2
)) != 0)
2785 if ((diff
= OBJECT_MAX (obj1
) - OBJECT_MAX (obj2
)) != 0)
2787 return ALLOCNO_NUM (a1
) - ALLOCNO_NUM (a2
);
2790 /* Sort ira_object_id_map and set up conflict id of allocnos. */
2792 sort_conflict_id_map (void)
2796 ira_allocno_iterator ai
;
2799 FOR_EACH_ALLOCNO (a
, ai
)
2801 ira_allocno_object_iterator oi
;
2804 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
2805 ira_object_id_map
[num
++] = obj
;
2808 qsort (ira_object_id_map
, num
, sizeof (ira_object_t
),
2809 object_range_compare_func
);
2810 for (i
= 0; i
< num
; i
++)
2812 ira_object_t obj
= ira_object_id_map
[i
];
2814 gcc_assert (obj
!= NULL
);
2815 OBJECT_CONFLICT_ID (obj
) = i
;
2817 for (i
= num
; i
< ira_objects_num
; i
++)
2818 ira_object_id_map
[i
] = NULL
;
2821 /* Set up minimal and maximal conflict ids of allocnos with which
2822 given allocno can conflict. */
2824 setup_min_max_conflict_allocno_ids (void)
2827 int i
, j
, min
, max
, start
, finish
, first_not_finished
, filled_area_start
;
2828 int *live_range_min
, *last_lived
;
2829 int word0_min
, word0_max
;
2831 ira_allocno_iterator ai
;
2833 live_range_min
= (int *) ira_allocate (sizeof (int) * ira_objects_num
);
2835 first_not_finished
= -1;
2836 for (i
= 0; i
< ira_objects_num
; i
++)
2838 ira_object_t obj
= ira_object_id_map
[i
];
2843 a
= OBJECT_ALLOCNO (obj
);
2847 aclass
= ALLOCNO_CLASS (a
);
2849 first_not_finished
= i
;
2853 start
= OBJECT_MIN (obj
);
2854 /* If we skip an allocno, the allocno with smaller ids will
2855 be also skipped because of the secondary sorting the
2856 range finishes (see function
2857 object_range_compare_func). */
2858 while (first_not_finished
< i
2859 && start
> OBJECT_MAX (ira_object_id_map
2860 [first_not_finished
]))
2861 first_not_finished
++;
2862 min
= first_not_finished
;
2865 /* We could increase min further in this case but it is good
2868 live_range_min
[i
] = OBJECT_MIN (obj
);
2869 OBJECT_MIN (obj
) = min
;
2871 last_lived
= (int *) ira_allocate (sizeof (int) * ira_max_point
);
2873 filled_area_start
= -1;
2874 for (i
= ira_objects_num
- 1; i
>= 0; i
--)
2876 ira_object_t obj
= ira_object_id_map
[i
];
2881 a
= OBJECT_ALLOCNO (obj
);
2884 aclass
= ALLOCNO_CLASS (a
);
2885 for (j
= 0; j
< ira_max_point
; j
++)
2887 filled_area_start
= ira_max_point
;
2889 min
= live_range_min
[i
];
2890 finish
= OBJECT_MAX (obj
);
2891 max
= last_lived
[finish
];
2893 /* We could decrease max further in this case but it is good
2895 max
= OBJECT_CONFLICT_ID (obj
) - 1;
2896 OBJECT_MAX (obj
) = max
;
2897 /* In filling, we can go further A range finish to recognize
2898 intersection quickly because if the finish of subsequently
2899 processed allocno (it has smaller conflict id) range is
2900 further A range finish than they are definitely intersected
2901 (the reason for this is the allocnos with bigger conflict id
2902 have their range starts not smaller than allocnos with
2904 for (j
= min
; j
< filled_area_start
; j
++)
2906 filled_area_start
= min
;
2908 ira_free (last_lived
);
2909 ira_free (live_range_min
);
2911 /* For allocnos with more than one object, we may later record extra conflicts in
2912 subobject 0 that we cannot really know about here.
2913 For now, simply widen the min/max range of these subobjects. */
2915 word0_min
= INT_MAX
;
2916 word0_max
= INT_MIN
;
2918 FOR_EACH_ALLOCNO (a
, ai
)
2920 int n
= ALLOCNO_NUM_OBJECTS (a
);
2925 obj0
= ALLOCNO_OBJECT (a
, 0);
2926 if (OBJECT_CONFLICT_ID (obj0
) < word0_min
)
2927 word0_min
= OBJECT_CONFLICT_ID (obj0
);
2928 if (OBJECT_CONFLICT_ID (obj0
) > word0_max
)
2929 word0_max
= OBJECT_CONFLICT_ID (obj0
);
2931 FOR_EACH_ALLOCNO (a
, ai
)
2933 int n
= ALLOCNO_NUM_OBJECTS (a
);
2938 obj0
= ALLOCNO_OBJECT (a
, 0);
2939 if (OBJECT_MIN (obj0
) > word0_min
)
2940 OBJECT_MIN (obj0
) = word0_min
;
2941 if (OBJECT_MAX (obj0
) < word0_max
)
2942 OBJECT_MAX (obj0
) = word0_max
;
2952 ira_allocno_iterator ai
;
2953 ira_loop_tree_node_t loop_tree_node
;
2955 FOR_EACH_ALLOCNO (a
, ai
)
2957 if (ALLOCNO_LOOP_TREE_NODE (a
) == ira_loop_tree_root
)
2959 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
2960 create_cap_allocno (a
);
2961 else if (ALLOCNO_CAP (a
) == NULL
)
2963 loop_tree_node
= ALLOCNO_LOOP_TREE_NODE (a
);
2964 if (!bitmap_bit_p (loop_tree_node
->border_allocnos
, ALLOCNO_NUM (a
)))
2965 create_cap_allocno (a
);
2972 /* The page contains code transforming more one region internal
2973 representation (IR) to one region IR which is necessary for reload.
2974 This transformation is called IR flattening. We might just rebuild
2975 the IR for one region but we don't do it because it takes a lot of
2978 /* Map: regno -> allocnos which will finally represent the regno for
2979 IR with one region. */
2980 static ira_allocno_t
*regno_top_level_allocno_map
;
2982 /* Find the allocno that corresponds to A at a level one higher up in the
2983 loop tree. Returns NULL if A is a cap, or if it has no parent. */
2985 ira_parent_allocno (ira_allocno_t a
)
2987 ira_loop_tree_node_t parent
;
2989 if (ALLOCNO_CAP (a
) != NULL
)
2992 parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
;
2996 return parent
->regno_allocno_map
[ALLOCNO_REGNO (a
)];
2999 /* Find the allocno that corresponds to A at a level one higher up in the
3000 loop tree. If ALLOCNO_CAP is set for A, return that. */
3002 ira_parent_or_cap_allocno (ira_allocno_t a
)
3004 if (ALLOCNO_CAP (a
) != NULL
)
3005 return ALLOCNO_CAP (a
);
3007 return ira_parent_allocno (a
);
3010 /* Process all allocnos originated from pseudo REGNO and copy live
3011 ranges, hard reg conflicts, and allocno stack reg attributes from
3012 low level allocnos to final allocnos which are destinations of
3013 removed stores at a loop exit. Return true if we copied live
3016 copy_info_to_removed_store_destinations (int regno
)
3019 ira_allocno_t parent_a
= NULL
;
3020 ira_loop_tree_node_t parent
;
3024 for (a
= ira_regno_allocno_map
[regno
];
3026 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
3028 if (a
!= regno_top_level_allocno_map
[REGNO (allocno_emit_reg (a
))])
3029 /* This allocno will be removed. */
3032 /* Caps will be removed. */
3033 ira_assert (ALLOCNO_CAP_MEMBER (a
) == NULL
);
3034 for (parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
;
3036 parent
= parent
->parent
)
3037 if ((parent_a
= parent
->regno_allocno_map
[regno
]) == NULL
3039 == regno_top_level_allocno_map
[REGNO
3040 (allocno_emit_reg (parent_a
))]
3041 && ALLOCNO_EMIT_DATA (parent_a
)->mem_optimized_dest_p
))
3043 if (parent
== NULL
|| parent_a
== NULL
)
3046 copy_allocno_live_ranges (a
, parent_a
);
3047 merge_hard_reg_conflicts (a
, parent_a
, true);
3049 ALLOCNO_CALL_FREQ (parent_a
) += ALLOCNO_CALL_FREQ (a
);
3050 ALLOCNO_CALLS_CROSSED_NUM (parent_a
)
3051 += ALLOCNO_CALLS_CROSSED_NUM (a
);
3052 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a
)
3053 += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
);
3054 IOR_HARD_REG_SET (ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (parent_a
),
3055 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
));
3056 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a
)
3057 += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
);
3063 /* Flatten the IR. In other words, this function transforms IR as if
3064 it were built with one region (without loops). We could make it
3065 much simpler by rebuilding IR with one region, but unfortunately it
3066 takes a lot of time. MAX_REGNO_BEFORE_EMIT and
3067 IRA_MAX_POINT_BEFORE_EMIT are correspondingly MAX_REG_NUM () and
3068 IRA_MAX_POINT before emitting insns on the loop borders. */
3070 ira_flattening (int max_regno_before_emit
, int ira_max_point_before_emit
)
3075 bool new_pseudos_p
, merged_p
, mem_dest_p
;
3077 enum reg_class aclass
;
3078 ira_allocno_t a
, parent_a
, first
, second
, node_first
, node_second
;
3080 ira_loop_tree_node_t node
;
3082 ira_allocno_iterator ai
;
3083 ira_copy_iterator ci
;
3085 regno_top_level_allocno_map
3086 = (ira_allocno_t
*) ira_allocate (max_reg_num ()
3087 * sizeof (ira_allocno_t
));
3088 memset (regno_top_level_allocno_map
, 0,
3089 max_reg_num () * sizeof (ira_allocno_t
));
3090 new_pseudos_p
= merged_p
= false;
3091 FOR_EACH_ALLOCNO (a
, ai
)
3093 ira_allocno_object_iterator oi
;
3096 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
3097 /* Caps are not in the regno allocno maps and they are never
3098 will be transformed into allocnos existing after IR
3101 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
3102 COPY_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
),
3103 OBJECT_CONFLICT_HARD_REGS (obj
));
3105 ALLOCNO_TOTAL_NO_STACK_REG_P (a
) = ALLOCNO_NO_STACK_REG_P (a
);
3108 /* Fix final allocno attributes. */
3109 for (i
= max_regno_before_emit
- 1; i
>= FIRST_PSEUDO_REGISTER
; i
--)
3112 for (a
= ira_regno_allocno_map
[i
];
3114 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
3116 ira_emit_data_t parent_data
, data
= ALLOCNO_EMIT_DATA (a
);
3118 ira_assert (ALLOCNO_CAP_MEMBER (a
) == NULL
);
3119 if (data
->somewhere_renamed_p
)
3120 new_pseudos_p
= true;
3121 parent_a
= ira_parent_allocno (a
);
3122 if (parent_a
== NULL
)
3124 ALLOCNO_COPIES (a
) = NULL
;
3125 regno_top_level_allocno_map
[REGNO (data
->reg
)] = a
;
3128 ira_assert (ALLOCNO_CAP_MEMBER (parent_a
) == NULL
);
3130 if (data
->mem_optimized_dest
!= NULL
)
3132 parent_data
= ALLOCNO_EMIT_DATA (parent_a
);
3133 if (REGNO (data
->reg
) == REGNO (parent_data
->reg
))
3135 merge_hard_reg_conflicts (a
, parent_a
, true);
3136 move_allocno_live_ranges (a
, parent_a
);
3138 parent_data
->mem_optimized_dest_p
3139 = (parent_data
->mem_optimized_dest_p
3140 || data
->mem_optimized_dest_p
);
3143 new_pseudos_p
= true;
3146 ALLOCNO_NREFS (parent_a
) -= ALLOCNO_NREFS (a
);
3147 ALLOCNO_FREQ (parent_a
) -= ALLOCNO_FREQ (a
);
3148 ALLOCNO_CALL_FREQ (parent_a
) -= ALLOCNO_CALL_FREQ (a
);
3149 ALLOCNO_CALLS_CROSSED_NUM (parent_a
)
3150 -= ALLOCNO_CALLS_CROSSED_NUM (a
);
3151 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a
)
3152 -= ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
);
3153 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a
)
3154 -= ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
);
3155 ira_assert (ALLOCNO_CALLS_CROSSED_NUM (parent_a
) >= 0
3156 && ALLOCNO_NREFS (parent_a
) >= 0
3157 && ALLOCNO_FREQ (parent_a
) >= 0);
3158 aclass
= ALLOCNO_CLASS (parent_a
);
3159 hard_regs_num
= ira_class_hard_regs_num
[aclass
];
3160 if (ALLOCNO_HARD_REG_COSTS (a
) != NULL
3161 && ALLOCNO_HARD_REG_COSTS (parent_a
) != NULL
)
3162 for (j
= 0; j
< hard_regs_num
; j
++)
3163 ALLOCNO_HARD_REG_COSTS (parent_a
)[j
]
3164 -= ALLOCNO_HARD_REG_COSTS (a
)[j
];
3165 if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) != NULL
3166 && ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a
) != NULL
)
3167 for (j
= 0; j
< hard_regs_num
; j
++)
3168 ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a
)[j
]
3169 -= ALLOCNO_CONFLICT_HARD_REG_COSTS (a
)[j
];
3170 ALLOCNO_CLASS_COST (parent_a
)
3171 -= ALLOCNO_CLASS_COST (a
);
3172 ALLOCNO_MEMORY_COST (parent_a
) -= ALLOCNO_MEMORY_COST (a
);
3173 parent_a
= ira_parent_allocno (parent_a
);
3174 if (parent_a
== NULL
)
3177 ALLOCNO_COPIES (a
) = NULL
;
3178 regno_top_level_allocno_map
[REGNO (data
->reg
)] = a
;
3180 if (mem_dest_p
&& copy_info_to_removed_store_destinations (i
))
3183 ira_assert (new_pseudos_p
|| ira_max_point_before_emit
== ira_max_point
);
3184 if (merged_p
|| ira_max_point_before_emit
!= ira_max_point
)
3185 ira_rebuild_start_finish_chains ();
3188 sparseset objects_live
;
3190 /* Rebuild conflicts. */
3191 FOR_EACH_ALLOCNO (a
, ai
)
3193 ira_allocno_object_iterator oi
;
3196 if (a
!= regno_top_level_allocno_map
[REGNO (allocno_emit_reg (a
))]
3197 || ALLOCNO_CAP_MEMBER (a
) != NULL
)
3199 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
3201 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
3202 ira_assert (r
->object
== obj
);
3203 clear_conflicts (obj
);
3206 objects_live
= sparseset_alloc (ira_objects_num
);
3207 for (i
= 0; i
< ira_max_point
; i
++)
3209 for (r
= ira_start_point_ranges
[i
]; r
!= NULL
; r
= r
->start_next
)
3211 ira_object_t obj
= r
->object
;
3213 a
= OBJECT_ALLOCNO (obj
);
3214 if (a
!= regno_top_level_allocno_map
[REGNO (allocno_emit_reg (a
))]
3215 || ALLOCNO_CAP_MEMBER (a
) != NULL
)
3218 aclass
= ALLOCNO_CLASS (a
);
3219 EXECUTE_IF_SET_IN_SPARSESET (objects_live
, n
)
3221 ira_object_t live_obj
= ira_object_id_map
[n
];
3222 ira_allocno_t live_a
= OBJECT_ALLOCNO (live_obj
);
3223 enum reg_class live_aclass
= ALLOCNO_CLASS (live_a
);
3225 if (ira_reg_classes_intersect_p
[aclass
][live_aclass
]
3226 /* Don't set up conflict for the allocno with itself. */
3228 ira_add_conflict (obj
, live_obj
);
3230 sparseset_set_bit (objects_live
, OBJECT_CONFLICT_ID (obj
));
3233 for (r
= ira_finish_point_ranges
[i
]; r
!= NULL
; r
= r
->finish_next
)
3234 sparseset_clear_bit (objects_live
, OBJECT_CONFLICT_ID (r
->object
));
3236 sparseset_free (objects_live
);
3237 compress_conflict_vecs ();
3239 /* Mark some copies for removing and change allocnos in the rest
3241 FOR_EACH_COPY (cp
, ci
)
3243 if (ALLOCNO_CAP_MEMBER (cp
->first
) != NULL
3244 || ALLOCNO_CAP_MEMBER (cp
->second
) != NULL
)
3246 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
3248 (ira_dump_file
, " Remove cp%d:%c%dr%d-%c%dr%d\n",
3249 cp
->num
, ALLOCNO_CAP_MEMBER (cp
->first
) != NULL
? 'c' : 'a',
3250 ALLOCNO_NUM (cp
->first
),
3251 REGNO (allocno_emit_reg (cp
->first
)),
3252 ALLOCNO_CAP_MEMBER (cp
->second
) != NULL
? 'c' : 'a',
3253 ALLOCNO_NUM (cp
->second
),
3254 REGNO (allocno_emit_reg (cp
->second
)));
3255 cp
->loop_tree_node
= NULL
;
3259 = regno_top_level_allocno_map
[REGNO (allocno_emit_reg (cp
->first
))];
3261 = regno_top_level_allocno_map
[REGNO (allocno_emit_reg (cp
->second
))];
3262 node
= cp
->loop_tree_node
;
3264 keep_p
= true; /* It copy generated in ira-emit.c. */
3267 /* Check that the copy was not propagated from level on
3268 which we will have different pseudos. */
3269 node_first
= node
->regno_allocno_map
[ALLOCNO_REGNO (cp
->first
)];
3270 node_second
= node
->regno_allocno_map
[ALLOCNO_REGNO (cp
->second
)];
3271 keep_p
= ((REGNO (allocno_emit_reg (first
))
3272 == REGNO (allocno_emit_reg (node_first
)))
3273 && (REGNO (allocno_emit_reg (second
))
3274 == REGNO (allocno_emit_reg (node_second
))));
3278 cp
->loop_tree_node
= ira_loop_tree_root
;
3280 cp
->second
= second
;
3284 cp
->loop_tree_node
= NULL
;
3285 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
3286 fprintf (ira_dump_file
, " Remove cp%d:a%dr%d-a%dr%d\n",
3287 cp
->num
, ALLOCNO_NUM (cp
->first
),
3288 REGNO (allocno_emit_reg (cp
->first
)),
3289 ALLOCNO_NUM (cp
->second
),
3290 REGNO (allocno_emit_reg (cp
->second
)));
3293 /* Remove unnecessary allocnos on lower levels of the loop tree. */
3294 FOR_EACH_ALLOCNO (a
, ai
)
3296 if (a
!= regno_top_level_allocno_map
[REGNO (allocno_emit_reg (a
))]
3297 || ALLOCNO_CAP_MEMBER (a
) != NULL
)
3299 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
3300 fprintf (ira_dump_file
, " Remove a%dr%d\n",
3301 ALLOCNO_NUM (a
), REGNO (allocno_emit_reg (a
)));
3302 ira_remove_allocno_prefs (a
);
3306 ALLOCNO_LOOP_TREE_NODE (a
) = ira_loop_tree_root
;
3307 ALLOCNO_REGNO (a
) = REGNO (allocno_emit_reg (a
));
3308 ALLOCNO_CAP (a
) = NULL
;
3309 /* Restore updated costs for assignments from reload. */
3310 ALLOCNO_UPDATED_MEMORY_COST (a
) = ALLOCNO_MEMORY_COST (a
);
3311 ALLOCNO_UPDATED_CLASS_COST (a
) = ALLOCNO_CLASS_COST (a
);
3312 if (! ALLOCNO_ASSIGNED_P (a
))
3313 ira_free_allocno_updated_costs (a
);
3314 ira_assert (ALLOCNO_UPDATED_HARD_REG_COSTS (a
) == NULL
);
3315 ira_assert (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) == NULL
);
3317 /* Remove unnecessary copies. */
3318 FOR_EACH_COPY (cp
, ci
)
3320 if (cp
->loop_tree_node
== NULL
)
3322 ira_copies
[cp
->num
] = NULL
;
3327 (ALLOCNO_LOOP_TREE_NODE (cp
->first
) == ira_loop_tree_root
3328 && ALLOCNO_LOOP_TREE_NODE (cp
->second
) == ira_loop_tree_root
);
3329 add_allocno_copy_to_list (cp
);
3330 swap_allocno_copy_ends_if_necessary (cp
);
3332 rebuild_regno_allocno_maps ();
3333 if (ira_max_point
!= ira_max_point_before_emit
)
3334 ira_compress_allocno_live_ranges ();
3335 ira_free (regno_top_level_allocno_map
);
3340 #ifdef ENABLE_IRA_CHECKING
3341 /* Check creation of all allocnos. Allocnos on lower levels should
3342 have allocnos or caps on all upper levels. */
3344 check_allocno_creation (void)
3347 ira_allocno_iterator ai
;
3348 ira_loop_tree_node_t loop_tree_node
;
3350 FOR_EACH_ALLOCNO (a
, ai
)
3352 loop_tree_node
= ALLOCNO_LOOP_TREE_NODE (a
);
3353 ira_assert (bitmap_bit_p (loop_tree_node
->all_allocnos
,
3355 if (loop_tree_node
== ira_loop_tree_root
)
3357 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
3358 ira_assert (ALLOCNO_CAP (a
) != NULL
);
3359 else if (ALLOCNO_CAP (a
) == NULL
)
3360 ira_assert (loop_tree_node
->parent
3361 ->regno_allocno_map
[ALLOCNO_REGNO (a
)] != NULL
3362 && bitmap_bit_p (loop_tree_node
->border_allocnos
,
3368 /* Identify allocnos which prefer a register class with a single hard register.
3369 Adjust ALLOCNO_CONFLICT_HARD_REG_COSTS so that conflicting allocnos are
3370 less likely to use the preferred singleton register. */
3372 update_conflict_hard_reg_costs (void)
3375 ira_allocno_iterator ai
;
3378 FOR_EACH_ALLOCNO (a
, ai
)
3380 reg_class_t aclass
= ALLOCNO_CLASS (a
);
3381 reg_class_t pref
= reg_preferred_class (ALLOCNO_REGNO (a
));
3382 int singleton
= ira_class_singleton
[pref
][ALLOCNO_MODE (a
)];
3385 index
= ira_class_hard_reg_index
[(int) aclass
][singleton
];
3388 if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) == NULL
3389 || ALLOCNO_HARD_REG_COSTS (a
) == NULL
)
3392 for (i
= ira_class_hard_regs_num
[(int) aclass
] - 1; i
>= 0; i
--)
3393 if (ALLOCNO_HARD_REG_COSTS (a
)[i
] > ALLOCNO_CLASS_COST (a
)
3394 && min
> ALLOCNO_HARD_REG_COSTS (a
)[i
])
3395 min
= ALLOCNO_HARD_REG_COSTS (a
)[i
];
3398 ira_allocate_and_set_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a
),
3400 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
)[index
]
3401 -= min
- ALLOCNO_CLASS_COST (a
);
3405 /* Create a internal representation (IR) for IRA (allocnos, copies,
3406 loop tree nodes). The function returns TRUE if we generate loop
3407 structure (besides nodes representing all function and the basic
3408 blocks) for regional allocation. A true return means that we
3409 really need to flatten IR before the reload. */
3416 initiate_cost_vectors ();
3417 initiate_allocnos ();
3420 create_loop_tree_nodes ();
3424 create_allocno_objects ();
3425 ira_create_allocno_live_ranges ();
3426 remove_unnecessary_regions (false);
3427 ira_compress_allocno_live_ranges ();
3428 update_bad_spill_attribute ();
3429 loops_p
= more_one_region_p ();
3432 propagate_allocno_info ();
3435 ira_tune_allocno_costs ();
3436 #ifdef ENABLE_IRA_CHECKING
3437 check_allocno_creation ();
3439 setup_min_max_allocno_live_range_point ();
3440 sort_conflict_id_map ();
3441 setup_min_max_conflict_allocno_ids ();
3442 ira_build_conflicts ();
3443 update_conflict_hard_reg_costs ();
3444 if (! ira_conflicts_p
)
3447 ira_allocno_iterator ai
;
3449 /* Remove all regions but root one. */
3452 remove_unnecessary_regions (true);
3455 /* We don't save hard registers around calls for fast allocation
3456 -- add caller clobbered registers as conflicting ones to
3457 allocno crossing calls. */
3458 FOR_EACH_ALLOCNO (a
, ai
)
3459 if (ALLOCNO_CALLS_CROSSED_NUM (a
) != 0)
3460 ior_hard_reg_conflicts (a
, &call_used_reg_set
);
3462 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
3463 print_copies (ira_dump_file
);
3464 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
3465 print_prefs (ira_dump_file
);
3466 if (internal_flag_ira_verbose
> 0 && ira_dump_file
!= NULL
)
3471 ira_allocno_iterator ai
;
3476 FOR_EACH_ALLOCNO (a
, ai
)
3478 int j
, nobj
= ALLOCNO_NUM_OBJECTS (a
);
3482 for (j
= 0; j
< nobj
; j
++)
3484 ira_object_t obj
= ALLOCNO_OBJECT (a
, j
);
3485 n
+= OBJECT_NUM_CONFLICTS (obj
);
3486 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
3490 fprintf (ira_dump_file
, " regions=%d, blocks=%d, points=%d\n",
3491 current_loops
== NULL
? 1 : number_of_loops (cfun
),
3492 n_basic_blocks_for_fn (cfun
), ira_max_point
);
3493 fprintf (ira_dump_file
,
3494 " allocnos=%d (big %d), copies=%d, conflicts=%d, ranges=%d\n",
3495 ira_allocnos_num
, nr_big
, ira_copies_num
, n
, nr
);
3500 /* Release the data created by function ira_build. */
3504 finish_loop_tree_nodes ();
3508 finish_cost_vectors ();
3509 ira_finish_allocno_live_ranges ();