2 * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Beladys spillalgorithm.
23 * @author Daniel Grund, Matthias Braun
31 #include "irprintf_t.h"
37 #include "iredges_t.h"
40 #include "irnodeset.h"
51 #include "bechordal_t.h"
53 #include "beloopana.h"
55 #include "bespillutil.h"
65 #define DBG_WORKSET 128
66 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
68 #define TIME_UNDEFINED 6666
71 * An association between a node and a point in time.
73 typedef struct loc_t {
75 unsigned time; /**< A use time (see beuses.h). */
76 bool spilled; /**< value was already spilled on this path */
79 typedef struct workset_t {
80 unsigned len; /**< current length */
81 loc_t vals[]; /**< array of the values/distances in this working set */
84 static struct obstack obst;
85 static const arch_register_class_t *cls;
86 static const be_lv_t *lv;
87 static be_loopana_t *loop_ana;
88 static unsigned n_regs;
89 static workset_t *ws; /**< the main workset used while
90 processing a block. */
91 static be_uses_t *uses; /**< env for the next-use magic */
92 static ir_node *instr; /**< current instruction */
93 static spill_env_t *senv; /**< see bespill.h */
94 static ir_node **blocklist;
96 static int move_spills = true;
97 static int respectloopdepth = true;
98 static int improve_known_preds = true;
99 /* factor to weight the different costs of reloading/rematerializing a node
100 (see bespill.h be_get_reload_costs_no_weight) */
101 static int remat_bonus = 10;
103 static const lc_opt_table_entry_t options[] = {
104 LC_OPT_ENT_BOOL ("movespills", "try to move spills out of loops", &move_spills),
105 LC_OPT_ENT_BOOL ("respectloopdepth", "outermost loop cutting", &respectloopdepth),
106 LC_OPT_ENT_BOOL ("improveknownpreds", "known preds cutting", &improve_known_preds),
107 LC_OPT_ENT_INT ("rematbonus", "give bonus to rematerialisable nodes", &remat_bonus),
112 * Alloc a new workset on obstack @p ob with maximum size @p max
114 static workset_t *new_workset(void)
116 return OALLOCFZ(&obst, workset_t, vals, n_regs);
120 * Alloc a new instance on obstack and make it equal to @param workset
122 static workset_t *workset_clone(workset_t *workset)
124 workset_t *res = OALLOCF(&obst, workset_t, vals, n_regs);
125 memcpy(res, workset, sizeof(*res) + n_regs * sizeof(res->vals[0]));
130 * Copy workset @param src to @param tgt
132 static void workset_copy(workset_t *dest, const workset_t *src)
134 size_t size = sizeof(*src) + n_regs * sizeof(src->vals[0]);
135 memcpy(dest, src, size);
139 * Overwrites the current content array of @param ws with the
140 * @param count locations given at memory @param locs.
141 * Set the length of @param ws to count.
143 static void workset_bulk_fill(workset_t *workset, int count, const loc_t *locs)
145 workset->len = count;
146 memcpy(&(workset->vals[0]), locs, count * sizeof(locs[0]));
150 * Inserts the value @p val into the workset, iff it is not
151 * already contained. The workset must not be full.
153 static void workset_insert(workset_t *workset, ir_node *val, bool spilled)
157 /* check for current regclass */
158 assert(arch_irn_consider_in_reg_alloc(cls, val));
160 /* check if val is already contained */
161 for (i = 0; i < workset->len; ++i) {
162 loc = &workset->vals[i];
163 if (loc->node == val) {
172 assert(workset->len < n_regs && "Workset already full!");
173 loc = &workset->vals[workset->len];
175 loc->spilled = spilled;
176 loc->time = TIME_UNDEFINED;
181 * Removes all entries from this workset
183 static void workset_clear(workset_t *workset)
189 * Removes the value @p val from the workset if present.
191 static void workset_remove(workset_t *workset, ir_node *val)
194 for (i = 0; i < workset->len; ++i) {
195 if (workset->vals[i].node == val) {
196 workset->vals[i] = workset->vals[--workset->len];
202 static const loc_t *workset_contains(const workset_t *ws, const ir_node *val)
205 for (i = 0; i < ws->len; ++i) {
206 if (ws->vals[i].node == val)
213 static int loc_compare(const void *a, const void *b)
215 const loc_t *p = ((const loc_t*) a);
216 const loc_t *q = ((const loc_t*) b);
217 const unsigned pt = p->time;
218 const unsigned qt = q->time;
225 return get_irn_node_nr(p->node) - get_irn_node_nr(q->node);
228 static void workset_sort(workset_t *workset)
230 qsort(workset->vals, workset->len, sizeof(workset->vals[0]), loc_compare);
233 static inline unsigned workset_get_time(const workset_t *workset, unsigned idx)
235 return workset->vals[idx].time;
238 static inline void workset_set_time(workset_t *workset, unsigned idx,
241 workset->vals[idx].time = time;
244 static inline unsigned workset_get_length(const workset_t *workset)
249 static inline void workset_set_length(workset_t *workset, unsigned len)
254 static inline ir_node *workset_get_val(const workset_t *workset, unsigned idx)
256 return workset->vals[idx].node;
260 * Iterates over all values in the working set.
261 * @p ws The workset to iterate
262 * @p v A variable to put the current value in
263 * @p i An integer for internal use
265 #define workset_foreach(ws, v, i) \
266 for (i=0; v=(i < ws->len) ? ws->vals[i].node : NULL, i < ws->len; ++i)
268 typedef struct block_info_t {
269 workset_t *start_workset;
270 workset_t *end_workset;
273 static block_info_t *new_block_info(void)
275 return OALLOCZ(&obst, block_info_t);
278 static inline block_info_t *get_block_info(const ir_node *block)
280 return (block_info_t*)get_irn_link(block);
283 static inline void set_block_info(ir_node *block, block_info_t *info)
285 set_irn_link(block, info);
289 * @return The distance to the next use or 0 if irn has dont_spill flag set
291 static unsigned get_distance(ir_node *from, const ir_node *def, int skip_from_uses)
297 assert(!arch_irn_is_ignore(def));
299 use = be_get_next_use(uses, from, def, skip_from_uses);
301 if (USES_IS_INFINITE(time))
302 return USES_INFINITY;
304 /* We have to keep nonspillable nodes in the workingset */
305 if (arch_get_irn_flags(skip_Proj_const(def)) & arch_irn_flags_dont_spill)
308 /* give some bonus to rematerialisable nodes */
309 if (remat_bonus > 0) {
310 costs = be_get_reload_costs_no_weight(senv, def, use.before);
311 assert(costs * remat_bonus < 1000);
312 time += 1000 - (costs * remat_bonus);
319 * Performs the actions necessary to grant the request that:
320 * - new_vals can be held in registers
321 * - as few as possible other values are disposed
322 * - the worst values get disposed
324 * @p is_usage indicates that the values in new_vals are used (not defined)
325 * In this case reloads must be performed
327 static void displace(workset_t *new_vals, int is_usage)
329 ir_node **to_insert = ALLOCAN(ir_node*, n_regs);
330 bool *spilled = ALLOCAN(bool, n_regs);
338 /* 1. Identify the number of needed slots and the values to reload */
340 workset_foreach(new_vals, val, iter) {
341 bool reloaded = false;
343 if (! workset_contains(ws, val)) {
344 DB((dbg, DBG_DECIDE, " insert %+F\n", val));
346 DB((dbg, DBG_SPILL, "Reload %+F before %+F\n", val, instr));
347 be_add_reload(senv, val, instr, cls, 1);
351 DB((dbg, DBG_DECIDE, " %+F already in workset\n", val));
353 /* remove the value from the current workset so it is not accidently
355 workset_remove(ws, val);
357 spilled[demand] = reloaded;
358 to_insert[demand] = val;
362 /* 2. Make room for at least 'demand' slots */
363 len = workset_get_length(ws);
364 spills_needed = len + demand - n_regs;
365 assert(spills_needed <= len);
367 /* Only make more free room if we do not have enough */
368 if (spills_needed > 0) {
369 DB((dbg, DBG_DECIDE, " disposing %d values\n", spills_needed));
371 /* calculate current next-use distance for live values */
372 for (i = 0; i < len; ++i) {
373 ir_node *val = workset_get_val(ws, i);
374 unsigned dist = get_distance(instr, val, !is_usage);
375 workset_set_time(ws, i, dist);
378 /* sort entries by increasing nextuse-distance*/
381 for (i = len - spills_needed; i < len; ++i) {
382 ir_node *val = ws->vals[i].node;
384 DB((dbg, DBG_DECIDE, " disposing node %+F (%u)\n", val,
385 workset_get_time(ws, i)));
388 if (!USES_IS_INFINITE(ws->vals[i].time)
389 && !ws->vals[i].spilled) {
390 ir_node *after_pos = sched_prev(instr);
391 DB((dbg, DBG_DECIDE, "Spill %+F after node %+F\n", val,
393 be_add_spill(senv, val, after_pos);
398 /* kill the last 'demand' entries in the array */
399 workset_set_length(ws, len - spills_needed);
402 /* 3. Insert the new values into the workset */
403 for (i = 0; i < demand; ++i) {
404 ir_node *val = to_insert[i];
406 workset_insert(ws, val, spilled[i]);
411 AVAILABLE_EVERYWHERE,
417 static unsigned available_in_all_preds(workset_t* const* pred_worksets,
418 size_t n_pred_worksets,
419 const ir_node *value, bool is_local_phi)
422 bool avail_everywhere = true;
423 bool avail_nowhere = true;
425 assert(n_pred_worksets > 0);
427 /* value available in all preds? */
428 for (i = 0; i < n_pred_worksets; ++i) {
430 const workset_t *p_workset = pred_worksets[i];
431 int p_len = workset_get_length(p_workset);
433 const ir_node *l_value;
436 assert(is_Phi(value));
437 l_value = get_irn_n(value, i);
442 for (p_i = 0; p_i < p_len; ++p_i) {
443 const loc_t *p_l = &p_workset->vals[p_i];
444 if (p_l->node != l_value)
452 avail_nowhere = false;
454 avail_everywhere = false;
458 if (avail_everywhere) {
459 assert(!avail_nowhere);
460 return AVAILABLE_EVERYWHERE;
461 } else if (avail_nowhere) {
462 return AVAILABLE_NOWHERE;
464 return AVAILABLE_PARTLY;
468 /** Decides whether a specific node should be in the start workset or not
470 * @param env belady environment
472 * @param node the node to test
473 * @param loop the loop of the node
475 static loc_t to_take_or_not_to_take(ir_node* first, ir_node *node,
476 ir_loop *loop, unsigned available)
478 be_next_use_t next_use;
481 loc.time = USES_INFINITY;
485 if (!arch_irn_consider_in_reg_alloc(cls, node)) {
486 loc.time = USES_INFINITY;
490 /* We have to keep nonspillable nodes in the workingset */
491 if (arch_get_irn_flags(skip_Proj_const(node)) & arch_irn_flags_dont_spill) {
493 DB((dbg, DBG_START, " %+F taken (dontspill node)\n", node, loc.time));
497 next_use = be_get_next_use(uses, first, node, 0);
498 if (USES_IS_INFINITE(next_use.time)) {
499 /* the nodes marked as live in shouldn't be dead, so it must be a phi */
500 assert(is_Phi(node));
501 loc.time = USES_INFINITY;
502 DB((dbg, DBG_START, " %+F not taken (dead)\n", node));
506 loc.time = next_use.time;
508 if (improve_known_preds) {
509 if (available == AVAILABLE_EVERYWHERE) {
510 DB((dbg, DBG_START, " %+F taken (%u, live in all preds)\n",
513 } else if (available == AVAILABLE_NOWHERE) {
514 DB((dbg, DBG_START, " %+F not taken (%u, live in no pred)\n",
516 loc.time = USES_INFINITY;
521 if (!respectloopdepth || next_use.outermost_loop >= get_loop_depth(loop)) {
522 DB((dbg, DBG_START, " %+F taken (%u, loop %d)\n", node, loc.time,
523 next_use.outermost_loop));
525 loc.time = USES_PENDING;
526 DB((dbg, DBG_START, " %+F delayed (outerdepth %d < loopdepth %d)\n",
527 node, next_use.outermost_loop, get_loop_depth(loop)));
534 * Computes the start-workset for a block with multiple predecessors. We assume
535 * that at least 1 of the predeccesors is a back-edge which means we're at the
536 * beginning of a loop. We try to reload as much values as possible now so they
537 * don't get reloaded inside the loop.
539 static void decide_start_workset(const ir_node *block)
541 ir_loop *loop = get_irn_loop(block);
550 int free_slots, free_pressure_slots;
553 workset_t **pred_worksets;
554 bool all_preds_known;
556 /* check predecessors */
557 arity = get_irn_arity(block);
558 pred_worksets = ALLOCAN(workset_t*, arity);
559 all_preds_known = true;
560 for (in = 0; in < arity; ++in) {
561 ir_node *pred_block = get_Block_cfgpred_block(block, in);
562 block_info_t *pred_info = get_block_info(pred_block);
564 if (pred_info == NULL) {
565 pred_worksets[in] = NULL;
566 all_preds_known = false;
568 pred_worksets[in] = pred_info->end_workset;
572 /* Collect all values living at start of block */
573 starters = NEW_ARR_F(loc_t, 0);
574 delayed = NEW_ARR_F(loc_t, 0);
576 DB((dbg, DBG_START, "Living at start of %+F:\n", block));
577 first = sched_first(block);
579 /* check all Phis first */
580 sched_foreach(block, node) {
585 if (!arch_irn_consider_in_reg_alloc(cls, node))
588 if (all_preds_known) {
589 available = available_in_all_preds(pred_worksets, arity, node, true);
591 available = AVAILABLE_UNKNOWN;
594 loc = to_take_or_not_to_take(first, node, loop, available);
596 if (! USES_IS_INFINITE(loc.time)) {
597 if (USES_IS_PENDING(loc.time))
598 ARR_APP1(loc_t, delayed, loc);
600 ARR_APP1(loc_t, starters, loc);
602 be_spill_phi(senv, node);
606 /* check all Live-Ins */
607 be_lv_foreach(lv, block, be_lv_state_in, in) {
608 ir_node *node = be_lv_get_irn(lv, block, in);
611 if (all_preds_known) {
612 available = available_in_all_preds(pred_worksets, arity, node, false);
614 available = AVAILABLE_UNKNOWN;
617 loc = to_take_or_not_to_take(first, node, loop, available);
619 if (! USES_IS_INFINITE(loc.time)) {
620 if (USES_IS_PENDING(loc.time))
621 ARR_APP1(loc_t, delayed, loc);
623 ARR_APP1(loc_t, starters, loc);
627 pressure = be_get_loop_pressure(loop_ana, cls, loop);
628 assert(ARR_LEN(delayed) <= pressure);
629 free_slots = n_regs - ARR_LEN(starters);
630 free_pressure_slots = n_regs - (pressure - ARR_LEN(delayed));
631 free_slots = MIN(free_slots, free_pressure_slots);
633 /* so far we only put nodes into the starters list that are used inside
634 * the loop. If register pressure in the loop is low then we can take some
635 * values and let them live through the loop */
636 DB((dbg, DBG_START, "Loop pressure %d, taking %d delayed vals\n",
637 pressure, free_slots));
638 if (free_slots > 0) {
641 qsort(delayed, ARR_LEN(delayed), sizeof(delayed[0]), loc_compare);
643 for (i = 0; i < ARR_LEN(delayed) && free_slots > 0; ++i) {
645 loc_t *loc = & delayed[i];
647 if (!is_Phi(loc->node)) {
648 /* don't use values which are dead in a known predecessors
649 * to not induce unnecessary reloads */
650 arity = get_irn_arity(block);
651 for (p = 0; p < arity; ++p) {
652 ir_node *pred_block = get_Block_cfgpred_block(block, p);
653 block_info_t *pred_info = get_block_info(pred_block);
655 if (pred_info == NULL)
658 if (!workset_contains(pred_info->end_workset, loc->node)) {
660 " delayed %+F not live at pred %+F\n", loc->node,
667 DB((dbg, DBG_START, " delayed %+F taken\n", loc->node));
668 ARR_APP1(loc_t, starters, *loc);
676 /* spill phis (the actual phis not just their values) that are in this block
677 * but not in the start workset */
678 len = ARR_LEN(delayed);
679 for (i = 0; i < len; ++i) {
680 ir_node *node = delayed[i].node;
681 if (node == NULL || !is_Phi(node) || get_nodes_block(node) != block)
684 DB((dbg, DBG_START, " spilling delayed phi %+F\n", node));
685 be_spill_phi(senv, node);
689 /* Sort start values by first use */
690 qsort(starters, ARR_LEN(starters), sizeof(starters[0]), loc_compare);
692 /* Copy the best ones from starters to start workset */
693 ws_count = MIN((unsigned) ARR_LEN(starters), n_regs);
695 workset_bulk_fill(ws, ws_count, starters);
697 /* spill phis (the actual phis not just their values) that are in this block
698 * but not in the start workset */
699 len = ARR_LEN(starters);
700 for (i = ws_count; i < len; ++i) {
701 ir_node *node = starters[i].node;
702 if (! is_Phi(node) || get_nodes_block(node) != block)
705 DB((dbg, DBG_START, " spilling phi %+F\n", node));
706 be_spill_phi(senv, node);
711 /* determine spill status of the values: If there's 1 pred block (which
712 * is no backedge) where the value is spilled then we must set it to
714 for (i = 0; i < ws_count; ++i) {
715 loc_t *loc = &ws->vals[i];
716 ir_node *value = loc->node;
720 /* phis from this block aren't spilled */
721 if (get_nodes_block(value) == block) {
722 assert(is_Phi(value));
723 loc->spilled = false;
727 /* determine if value was spilled on any predecessor */
729 for (n = 0; n < arity; ++n) {
730 workset_t *pred_workset = pred_worksets[n];
734 if (pred_workset == NULL)
737 p_len = workset_get_length(pred_workset);
738 for (p = 0; p < p_len; ++p) {
739 loc_t *l = &pred_workset->vals[p];
741 if (l->node != value)
751 loc->spilled = spilled;
756 * For the given block @p block, decide for each values
757 * whether it is used from a register or is reloaded
760 static void process_block(ir_node *block)
764 block_info_t *block_info;
767 /* no need to process a block twice */
768 assert(get_block_info(block) == NULL);
770 /* construct start workset */
771 arity = get_Block_n_cfgpreds(block);
773 /* no predecessor -> empty set */
775 } else if (arity == 1) {
776 /* one predecessor, copy its end workset */
777 ir_node *pred_block = get_Block_cfgpred_block(block, 0);
778 block_info_t *pred_info = get_block_info(pred_block);
780 assert(pred_info != NULL);
781 workset_copy(ws, pred_info->end_workset);
783 /* multiple predecessors, do more advanced magic :) */
784 decide_start_workset(block);
787 DB((dbg, DBG_DECIDE, "\n"));
788 DB((dbg, DBG_DECIDE, "Decide for %+F\n", block));
790 block_info = new_block_info();
791 set_block_info(block, block_info);
793 DB((dbg, DBG_WSETS, "Start workset for %+F:\n", block));
796 workset_foreach(ws, irn, iter) {
797 DB((dbg, DBG_WSETS, " %+F (%u)\n", irn, workset_get_time(ws, iter)));
801 block_info->start_workset = workset_clone(ws);
803 /* process the block from start to end */
804 DB((dbg, DBG_WSETS, "Processing...\n"));
805 /* TODO: this leaks (into the obstack)... */
806 new_vals = new_workset();
808 sched_foreach(block, irn) {
811 assert(workset_get_length(ws) <= n_regs);
813 /* Phis are no real instr (see insert_starters()) */
817 DB((dbg, DBG_DECIDE, " ...%+F\n", irn));
819 /* set instruction in the workset */
822 /* allocate all values _used_ by this instruction */
823 workset_clear(new_vals);
824 for (i = 0, arity = get_irn_arity(irn); i < arity; ++i) {
825 ir_node *in = get_irn_n(irn, i);
826 if (!arch_irn_consider_in_reg_alloc(cls, in))
829 /* (note that "spilled" is irrelevant here) */
830 workset_insert(new_vals, in, false);
832 displace(new_vals, 1);
834 /* allocate all values _defined_ by this instruction */
835 workset_clear(new_vals);
836 be_foreach_definition(irn, cls, value,
837 assert(req_->width == 1);
838 workset_insert(new_vals, value, false);
840 displace(new_vals, 0);
843 /* Remember end-workset for this block */
844 block_info->end_workset = workset_clone(ws);
845 DB((dbg, DBG_WSETS, "End workset for %+F:\n", block));
848 workset_foreach(ws, irn, iter)
849 DB((dbg, DBG_WSETS, " %+F (%u)\n", irn, workset_get_time(ws, iter)));
854 * 'decide' is block-local and makes assumptions
855 * about the set of live-ins. Thus we must adapt the
856 * live-outs to the live-ins at each block-border.
858 static void fix_block_borders(ir_node *block, void *data)
860 workset_t *start_workset;
866 DB((dbg, DBG_FIX, "\n"));
867 DB((dbg, DBG_FIX, "Fixing %+F\n", block));
869 arity = get_irn_arity(block);
870 /* can happen for endless loops */
874 start_workset = get_block_info(block)->start_workset;
876 /* process all pred blocks */
877 for (i = 0; i < arity; ++i) {
878 ir_node *pred = get_Block_cfgpred_block(block, i);
879 workset_t *pred_end_workset = get_block_info(pred)->end_workset;
882 DB((dbg, DBG_FIX, " Pred %+F\n", pred));
884 /* spill all values not used anymore */
885 workset_foreach(pred_end_workset, node, iter) {
889 workset_foreach(start_workset, n2, iter2) {
894 /* note that we do not look at phi inputs, becuase the values
895 * will be either live-end and need no spill or
896 * they have other users in which must be somewhere else in the
903 if (move_spills && be_is_live_in(lv, block, node)
904 && !pred_end_workset->vals[iter].spilled) {
905 ir_node *insert_point;
907 insert_point = be_get_end_of_block_insertion_point(pred);
908 insert_point = sched_prev(insert_point);
910 insert_point = block;
912 DB((dbg, DBG_SPILL, "Spill %+F after %+F\n", node,
914 be_add_spill(senv, node, insert_point);
918 /* reload missing values in predecessors, add missing spills */
919 workset_foreach(start_workset, node, iter) {
920 const loc_t *l = &start_workset->vals[iter];
921 const loc_t *pred_loc;
923 /* if node is a phi of the current block we reload
924 * the corresponding argument, else node itself */
925 if (is_Phi(node) && get_nodes_block(node) == block) {
926 node = get_irn_n(node, i);
929 /* we might have unknowns as argument for the phi */
930 if (!arch_irn_consider_in_reg_alloc(cls, node))
934 /* check if node is in a register at end of pred */
935 pred_loc = workset_contains(pred_end_workset, node);
936 if (pred_loc != NULL) {
937 /* we might have to spill value on this path */
938 if (move_spills && !pred_loc->spilled && l->spilled) {
939 ir_node *insert_point
940 = be_get_end_of_block_insertion_point(pred);
941 insert_point = sched_prev(insert_point);
942 DB((dbg, DBG_SPILL, "Spill %+F after %+F\n", node,
944 be_add_spill(senv, node, insert_point);
947 /* node is not in register at the end of pred -> reload it */
948 DB((dbg, DBG_FIX, " reload %+F\n", node));
949 DB((dbg, DBG_SPILL, "Reload %+F before %+F,%d\n", node, block, i));
950 be_add_reload_on_edge(senv, node, block, i, cls, 1);
956 static void be_spill_belady(ir_graph *irg, const arch_register_class_t *rcls)
960 be_assure_live_sets(irg);
963 assure_loopinfo(irg);
964 stat_ev_tim_pop("belady_time_backedges");
968 stat_ev_tim_pop("belady_time_clear_links");
970 ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
972 /* init belady env */
976 lv = be_get_irg_liveness(irg);
977 n_regs = be_get_n_allocatable_regs(irg, cls);
979 uses = be_begin_uses(irg, lv);
980 loop_ana = be_new_loop_pressure(irg, cls);
981 senv = be_new_spill_env(irg);
982 blocklist = be_get_cfgpostorder(irg);
983 stat_ev_tim_pop("belady_time_init");
986 /* walk blocks in reverse postorder */
987 for (i = ARR_LEN(blocklist) - 1; i >= 0; --i) {
988 process_block(blocklist[i]);
990 DEL_ARR_F(blocklist);
991 stat_ev_tim_pop("belady_time_belady");
994 /* belady was block-local, fix the global flow by adding reloads on the
996 irg_block_walk_graph(irg, fix_block_borders, NULL, NULL);
997 stat_ev_tim_pop("belady_time_fix_borders");
999 ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
1001 /* Insert spill/reload nodes into the graph and fix usages */
1002 be_insert_spills_reloads(senv);
1005 be_delete_spill_env(senv);
1007 be_free_loop_pressure(loop_ana);
1008 obstack_free(&obst, NULL);
1011 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillbelady)
1012 void be_init_spillbelady(void)
1014 static be_spiller_t belady_spiller = {
1017 lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
1018 lc_opt_entry_t *belady_group = lc_opt_get_grp(be_grp, "belady");
1019 lc_opt_add_table(belady_group, options);
1021 be_register_spiller("belady", &belady_spiller);
1022 FIRM_DBG_REGISTER(dbg, "firm.be.spill.belady");