2 * Copyright (C) 1995-2008 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
32 #include "irprintf_t.h"
38 #include "iredges_t.h"
41 #include "irnodeset.h"
50 #include "bechordal_t.h"
52 #include "beloopana.h"
54 #include "bespillutil.h"
64 #define DBG_WORKSET 128
65 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
67 #define TIME_UNDEFINED 6666
70 * An association between a node and a point in time.
72 typedef struct loc_t {
74 unsigned time; /**< A use time (see beuses.h). */
75 bool spilled; /**< value was already spilled on this path */
78 typedef struct workset_t {
79 unsigned len; /**< current length */
80 loc_t vals[0]; /**< array of the values/distances in this working set */
83 static struct obstack obst;
84 static const arch_register_class_t *cls;
85 static const be_lv_t *lv;
86 static be_loopana_t *loop_ana;
87 static unsigned n_regs;
88 static workset_t *ws; /**< the main workset used while
89 processing a block. */
90 static be_uses_t *uses; /**< env for the next-use magic */
91 static ir_node *instr; /**< current instruction */
92 static unsigned instr_nr; /**< current instruction number
93 (relative to block start) */
94 static spill_env_t *senv; /**< see bespill.h */
95 static ir_node **blocklist;
97 static int move_spills = true;
98 static int respectloopdepth = true;
99 static int improve_known_preds = true;
100 /* factor to weight the different costs of reloading/rematerializing a node
101 (see bespill.h be_get_reload_costs_no_weight) */
102 static int remat_bonus = 10;
104 static const lc_opt_table_entry_t options[] = {
105 LC_OPT_ENT_BOOL ("movespills", "try to move spills out of loops", &move_spills),
106 LC_OPT_ENT_BOOL ("respectloopdepth", "outermost loop cutting", &respectloopdepth),
107 LC_OPT_ENT_BOOL ("improveknownpreds", "known preds cutting", &improve_known_preds),
108 LC_OPT_ENT_INT ("rematbonus", "give bonus to rematerialisable nodes", &remat_bonus),
113 * Alloc a new workset on obstack @p ob with maximum size @p max
115 static workset_t *new_workset(void)
117 return OALLOCFZ(&obst, workset_t, vals, n_regs);
121 * Alloc a new instance on obstack and make it equal to @param workset
123 static workset_t *workset_clone(workset_t *workset)
125 workset_t *res = OALLOCF(&obst, workset_t, vals, n_regs);
126 memcpy(res, workset, sizeof(*res) + n_regs * sizeof(res->vals[0]));
131 * Copy workset @param src to @param tgt
133 static void workset_copy(workset_t *dest, const workset_t *src)
135 size_t size = sizeof(*src) + n_regs * sizeof(src->vals[0]);
136 memcpy(dest, src, size);
140 * Overwrites the current content array of @param ws with the
141 * @param count locations given at memory @param locs.
142 * Set the length of @param ws to count.
144 static void workset_bulk_fill(workset_t *workset, int count, const loc_t *locs)
146 workset->len = count;
147 memcpy(&(workset->vals[0]), locs, count * sizeof(locs[0]));
151 * Inserts the value @p val into the workset, iff it is not
152 * already contained. The workset must not be full.
154 static void workset_insert(workset_t *workset, ir_node *val, bool spilled)
158 /* check for current regclass */
159 assert(arch_irn_consider_in_reg_alloc(cls, val));
161 /* check if val is already contained */
162 for (i = 0; i < workset->len; ++i) {
163 loc = &workset->vals[i];
164 if (loc->node == val) {
173 assert(workset->len < n_regs && "Workset already full!");
174 loc = &workset->vals[workset->len];
176 loc->spilled = spilled;
177 loc->time = TIME_UNDEFINED;
182 * Removes all entries from this workset
184 static void workset_clear(workset_t *workset)
190 * Removes the value @p val from the workset if present.
192 static void workset_remove(workset_t *workset, ir_node *val)
195 for (i = 0; i < workset->len; ++i) {
196 if (workset->vals[i].node == val) {
197 workset->vals[i] = workset->vals[--workset->len];
203 static const loc_t *workset_contains(const workset_t *ws, const ir_node *val)
206 for (i = 0; i < ws->len; ++i) {
207 if (ws->vals[i].node == val)
214 static int loc_compare(const void *a, const void *b)
218 return p->time - q->time;
221 static void workset_sort(workset_t *workset)
223 qsort(workset->vals, workset->len, sizeof(workset->vals[0]), loc_compare);
226 static inline unsigned workset_get_time(const workset_t *workset, unsigned idx)
228 return workset->vals[idx].time;
231 static inline void workset_set_time(workset_t *workset, unsigned idx,
234 workset->vals[idx].time = time;
237 static inline unsigned workset_get_length(const workset_t *workset)
242 static inline void workset_set_length(workset_t *workset, unsigned len)
247 static inline ir_node *workset_get_val(const workset_t *workset, unsigned idx)
249 return workset->vals[idx].node;
253 * Iterates over all values in the working set.
254 * @p ws The workset to iterate
255 * @p v A variable to put the current value in
256 * @p i An integer for internal use
258 #define workset_foreach(ws, v, i) \
259 for (i=0; v=(i < ws->len) ? ws->vals[i].node : NULL, i < ws->len; ++i)
261 typedef struct block_info_t {
262 workset_t *start_workset;
263 workset_t *end_workset;
266 static block_info_t *new_block_info(void)
268 return OALLOCZ(&obst, block_info_t);
271 static inline block_info_t *get_block_info(const ir_node *block)
273 return get_irn_link(block);
276 static inline void set_block_info(ir_node *block, block_info_t *info)
278 set_irn_link(block, info);
282 * @return The distance to the next use or 0 if irn has dont_spill flag set
284 static unsigned get_distance(ir_node *from, unsigned from_step,
285 const ir_node *def, int skip_from_uses)
291 assert(!arch_irn_is_ignore(def));
293 use = be_get_next_use(uses, from, from_step, def, skip_from_uses);
295 if (USES_IS_INFINITE(time))
296 return USES_INFINITY;
298 /* We have to keep nonspillable nodes in the workingset */
299 if (arch_irn_get_flags(skip_Proj_const(def)) & arch_irn_flags_dont_spill)
302 /* give some bonus to rematerialisable nodes */
303 if (remat_bonus > 0) {
304 costs = be_get_reload_costs_no_weight(senv, def, use.before);
305 assert(costs * remat_bonus < 1000);
306 time += 1000 - (costs * remat_bonus);
313 * Performs the actions necessary to grant the request that:
314 * - new_vals can be held in registers
315 * - as few as possible other values are disposed
316 * - the worst values get disposed
318 * @p is_usage indicates that the values in new_vals are used (not defined)
319 * In this case reloads must be performed
321 static void displace(workset_t *new_vals, int is_usage)
323 ir_node **to_insert = ALLOCAN(ir_node*, n_regs);
324 bool *spilled = ALLOCAN(bool, n_regs);
332 /* 1. Identify the number of needed slots and the values to reload */
334 workset_foreach(new_vals, val, iter) {
335 bool reloaded = false;
337 if (! workset_contains(ws, val)) {
338 DB((dbg, DBG_DECIDE, " insert %+F\n", val));
340 DB((dbg, DBG_SPILL, "Reload %+F before %+F\n", val, instr));
341 be_add_reload(senv, val, instr, cls, 1);
345 DB((dbg, DBG_DECIDE, " %+F already in workset\n", val));
347 /* remove the value from the current workset so it is not accidently
349 workset_remove(ws, val);
351 spilled[demand] = reloaded;
352 to_insert[demand] = val;
356 /* 2. Make room for at least 'demand' slots */
357 len = workset_get_length(ws);
358 spills_needed = len + demand - n_regs;
359 assert(spills_needed <= len);
361 /* Only make more free room if we do not have enough */
362 if (spills_needed > 0) {
363 DB((dbg, DBG_DECIDE, " disposing %d values\n", spills_needed));
365 /* calculate current next-use distance for live values */
366 for (i = 0; i < len; ++i) {
367 ir_node *val = workset_get_val(ws, i);
368 unsigned dist = get_distance(instr, instr_nr, val, !is_usage);
369 workset_set_time(ws, i, dist);
372 /* sort entries by increasing nextuse-distance*/
375 for (i = len - spills_needed; i < len; ++i) {
376 ir_node *val = ws->vals[i].node;
378 DB((dbg, DBG_DECIDE, " disposing node %+F (%u)\n", val,
379 workset_get_time(ws, i)));
382 if (!USES_IS_INFINITE(ws->vals[i].time)
383 && !ws->vals[i].spilled) {
384 ir_node *after_pos = sched_prev(instr);
385 DB((dbg, DBG_DECIDE, "Spill %+F after node %+F\n", val,
387 be_add_spill(senv, val, after_pos);
392 /* kill the last 'demand' entries in the array */
393 workset_set_length(ws, len - spills_needed);
396 /* 3. Insert the new values into the workset */
397 for (i = 0; i < demand; ++i) {
398 ir_node *val = to_insert[i];
400 workset_insert(ws, val, spilled[i]);
405 AVAILABLE_EVERYWHERE,
411 static unsigned available_in_all_preds(workset_t* const* pred_worksets,
412 size_t n_pred_worksets,
413 const ir_node *value, bool is_local_phi)
416 bool avail_everywhere = true;
417 bool avail_nowhere = true;
419 assert(n_pred_worksets > 0);
421 /* value available in all preds? */
422 for (i = 0; i < n_pred_worksets; ++i) {
424 const workset_t *p_workset = pred_worksets[i];
425 int p_len = workset_get_length(p_workset);
427 const ir_node *l_value;
430 assert(is_Phi(value));
431 l_value = get_irn_n(value, i);
436 for (p_i = 0; p_i < p_len; ++p_i) {
437 const loc_t *p_l = &p_workset->vals[p_i];
438 if (p_l->node != l_value)
446 avail_nowhere = false;
448 avail_everywhere = false;
452 if (avail_everywhere) {
453 assert(!avail_nowhere);
454 return AVAILABLE_EVERYWHERE;
455 } else if (avail_nowhere) {
456 return AVAILABLE_NOWHERE;
458 return AVAILABLE_PARTLY;
462 /** Decides whether a specific node should be in the start workset or not
464 * @param env belady environment
466 * @param node the node to test
467 * @param loop the loop of the node
469 static loc_t to_take_or_not_to_take(ir_node* first, ir_node *node,
470 ir_loop *loop, unsigned available)
472 be_next_use_t next_use;
475 loc.time = USES_INFINITY;
479 if (!arch_irn_consider_in_reg_alloc(cls, node)) {
480 loc.time = USES_INFINITY;
484 /* We have to keep nonspillable nodes in the workingset */
485 if (arch_irn_get_flags(skip_Proj_const(node)) & arch_irn_flags_dont_spill) {
487 DB((dbg, DBG_START, " %+F taken (dontspill node)\n", node, loc.time));
491 next_use = be_get_next_use(uses, first, 0, node, 0);
492 if (USES_IS_INFINITE(next_use.time)) {
493 /* the nodes marked as live in shouldn't be dead, so it must be a phi */
494 assert(is_Phi(node));
495 loc.time = USES_INFINITY;
496 DB((dbg, DBG_START, " %+F not taken (dead)\n", node));
500 loc.time = next_use.time;
502 if (improve_known_preds) {
503 if (available == AVAILABLE_EVERYWHERE) {
504 DB((dbg, DBG_START, " %+F taken (%u, live in all preds)\n",
507 } else if (available == AVAILABLE_NOWHERE) {
508 DB((dbg, DBG_START, " %+F not taken (%u, live in no pred)\n",
510 loc.time = USES_INFINITY;
515 if (!respectloopdepth || next_use.outermost_loop >= get_loop_depth(loop)) {
516 DB((dbg, DBG_START, " %+F taken (%u, loop %d)\n", node, loc.time,
517 next_use.outermost_loop));
519 loc.time = USES_PENDING;
520 DB((dbg, DBG_START, " %+F delayed (outerdepth %d < loopdepth %d)\n",
521 node, next_use.outermost_loop, get_loop_depth(loop)));
528 * Computes the start-workset for a block with multiple predecessors. We assume
529 * that at least 1 of the predeccesors is a back-edge which means we're at the
530 * beginning of a loop. We try to reload as much values as possible now so they
531 * don't get reloaded inside the loop.
533 static void decide_start_workset(const ir_node *block)
535 ir_loop *loop = get_irn_loop(block);
545 int free_slots, free_pressure_slots;
548 workset_t **pred_worksets;
549 bool all_preds_known;
551 /* check predecessors */
552 arity = get_irn_arity(block);
553 pred_worksets = ALLOCAN(workset_t*, arity);
554 all_preds_known = true;
555 for (in = 0; in < arity; ++in) {
556 ir_node *pred_block = get_Block_cfgpred_block(block, in);
557 block_info_t *pred_info = get_block_info(pred_block);
559 if (pred_info == NULL) {
560 pred_worksets[in] = NULL;
561 all_preds_known = false;
563 pred_worksets[in] = pred_info->end_workset;
567 /* Collect all values living at start of block */
568 starters = NEW_ARR_F(loc_t, 0);
569 delayed = NEW_ARR_F(loc_t, 0);
571 DB((dbg, DBG_START, "Living at start of %+F:\n", block));
572 first = sched_first(block);
574 /* check all Phis first */
575 sched_foreach(block, node) {
580 if (!arch_irn_consider_in_reg_alloc(cls, node))
583 if (all_preds_known) {
584 available = available_in_all_preds(pred_worksets, arity, node, true);
586 available = AVAILABLE_UNKNOWN;
589 loc = to_take_or_not_to_take(first, node, loop, available);
591 if (! USES_IS_INFINITE(loc.time)) {
592 if (USES_IS_PENDING(loc.time))
593 ARR_APP1(loc_t, delayed, loc);
595 ARR_APP1(loc_t, starters, loc);
597 be_spill_phi(senv, node);
601 /* check all Live-Ins */
602 be_lv_foreach(lv, block, be_lv_state_in, in) {
603 ir_node *node = be_lv_get_irn(lv, block, in);
606 if (all_preds_known) {
607 available = available_in_all_preds(pred_worksets, arity, node, false);
609 available = AVAILABLE_UNKNOWN;
612 loc = to_take_or_not_to_take(first, node, loop, available);
614 if (! USES_IS_INFINITE(loc.time)) {
615 if (USES_IS_PENDING(loc.time))
616 ARR_APP1(loc_t, delayed, loc);
618 ARR_APP1(loc_t, starters, loc);
622 pressure = be_get_loop_pressure(loop_ana, cls, loop);
623 assert(ARR_LEN(delayed) <= (signed)pressure);
624 free_slots = n_regs - ARR_LEN(starters);
625 free_pressure_slots = n_regs - (pressure - ARR_LEN(delayed));
626 free_slots = MIN(free_slots, free_pressure_slots);
628 /* so far we only put nodes into the starters list that are used inside
629 * the loop. If register pressure in the loop is low then we can take some
630 * values and let them live through the loop */
631 DB((dbg, DBG_START, "Loop pressure %d, taking %d delayed vals\n",
632 pressure, free_slots));
633 if (free_slots > 0) {
635 qsort(delayed, ARR_LEN(delayed), sizeof(delayed[0]), loc_compare);
637 for (i = 0; i < ARR_LEN(delayed) && free_slots > 0; ++i) {
639 loc_t *loc = & delayed[i];
641 if (!is_Phi(loc->node)) {
642 /* don't use values which are dead in a known predecessors
643 * to not induce unnecessary reloads */
644 arity = get_irn_arity(block);
645 for (p = 0; p < arity; ++p) {
646 ir_node *pred_block = get_Block_cfgpred_block(block, p);
647 block_info_t *pred_info = get_block_info(pred_block);
649 if (pred_info == NULL)
652 if (!workset_contains(pred_info->end_workset, loc->node)) {
654 " delayed %+F not live at pred %+F\n", loc->node,
661 DB((dbg, DBG_START, " delayed %+F taken\n", loc->node));
662 ARR_APP1(loc_t, starters, *loc);
670 /* spill phis (the actual phis not just their values) that are in this block
671 * but not in the start workset */
672 len = ARR_LEN(delayed);
673 for (i = 0; i < len; ++i) {
674 ir_node *node = delayed[i].node;
675 if (node == NULL || !is_Phi(node) || get_nodes_block(node) != block)
678 DB((dbg, DBG_START, " spilling delayed phi %+F\n", node));
679 be_spill_phi(senv, node);
683 /* Sort start values by first use */
684 qsort(starters, ARR_LEN(starters), sizeof(starters[0]), loc_compare);
686 /* Copy the best ones from starters to start workset */
687 ws_count = MIN((unsigned) ARR_LEN(starters), n_regs);
689 workset_bulk_fill(ws, ws_count, starters);
691 /* spill phis (the actual phis not just their values) that are in this block
692 * but not in the start workset */
693 len = ARR_LEN(starters);
694 for (i = ws_count; i < len; ++i) {
695 ir_node *node = starters[i].node;
696 if (! is_Phi(node) || get_nodes_block(node) != block)
699 DB((dbg, DBG_START, " spilling phi %+F\n", node));
700 be_spill_phi(senv, node);
705 /* determine spill status of the values: If there's 1 pred block (which
706 * is no backedge) where the value is spilled then we must set it to
708 for (i = 0; i < ws_count; ++i) {
709 loc_t *loc = &ws->vals[i];
710 ir_node *value = loc->node;
714 /* phis from this block aren't spilled */
715 if (get_nodes_block(value) == block) {
716 assert(is_Phi(value));
717 loc->spilled = false;
721 /* determine if value was spilled on any predecessor */
723 for (n = 0; n < arity; ++n) {
724 workset_t *pred_workset = pred_worksets[n];
728 if (pred_workset == NULL)
731 p_len = workset_get_length(pred_workset);
732 for (p = 0; p < p_len; ++p) {
733 loc_t *l = &pred_workset->vals[p];
735 if (l->node != value)
745 loc->spilled = spilled;
750 * For the given block @p block, decide for each values
751 * whether it is used from a register or is reloaded
754 static void process_block(ir_node *block)
759 block_info_t *block_info;
762 /* no need to process a block twice */
763 assert(get_block_info(block) == NULL);
765 /* construct start workset */
766 arity = get_Block_n_cfgpreds(block);
768 /* no predecessor -> empty set */
770 } else if (arity == 1) {
771 /* one predecessor, copy it's end workset */
772 ir_node *pred_block = get_Block_cfgpred_block(block, 0);
773 block_info_t *pred_info = get_block_info(pred_block);
775 assert(pred_info != NULL);
776 workset_copy(ws, pred_info->end_workset);
778 /* multiple predecessors, do more advanced magic :) */
779 decide_start_workset(block);
782 DB((dbg, DBG_DECIDE, "\n"));
783 DB((dbg, DBG_DECIDE, "Decide for %+F\n", block));
785 block_info = new_block_info();
786 set_block_info(block, block_info);
788 DB((dbg, DBG_WSETS, "Start workset for %+F:\n", block));
789 workset_foreach(ws, irn, iter) {
790 DB((dbg, DBG_WSETS, " %+F (%u)\n", irn,
791 workset_get_time(ws, iter)));
794 block_info->start_workset = workset_clone(ws);
796 /* process the block from start to end */
797 DB((dbg, DBG_WSETS, "Processing...\n"));
799 /* TODO: this leaks (into the obstack)... */
800 new_vals = new_workset();
802 sched_foreach(block, irn) {
805 assert(workset_get_length(ws) <= n_regs);
807 /* Phis are no real instr (see insert_starters()) */
811 DB((dbg, DBG_DECIDE, " ...%+F\n", irn));
813 /* set instruction in the workset */
816 /* allocate all values _used_ by this instruction */
817 workset_clear(new_vals);
818 for (i = 0, arity = get_irn_arity(irn); i < arity; ++i) {
819 ir_node *in = get_irn_n(irn, i);
820 if (!arch_irn_consider_in_reg_alloc(cls, in))
823 /* (note that "spilled" is irrelevant here) */
824 workset_insert(new_vals, in, false);
826 displace(new_vals, 1);
828 /* allocate all values _defined_ by this instruction */
829 workset_clear(new_vals);
830 be_foreach_definition(irn, cls, value,
831 assert(req_->width == 1);
832 workset_insert(new_vals, value, false);
834 displace(new_vals, 0);
839 /* Remember end-workset for this block */
840 block_info->end_workset = workset_clone(ws);
841 DB((dbg, DBG_WSETS, "End workset for %+F:\n", block));
842 workset_foreach(ws, irn, iter)
843 DB((dbg, DBG_WSETS, " %+F (%u)\n", irn, workset_get_time(ws, iter)));
847 * 'decide' is block-local and makes assumptions
848 * about the set of live-ins. Thus we must adapt the
849 * live-outs to the live-ins at each block-border.
851 static void fix_block_borders(ir_node *block, void *data)
853 workset_t *start_workset;
859 DB((dbg, DBG_FIX, "\n"));
860 DB((dbg, DBG_FIX, "Fixing %+F\n", block));
862 arity = get_irn_arity(block);
863 /* can happen for endless loops */
867 start_workset = get_block_info(block)->start_workset;
869 /* process all pred blocks */
870 for (i = 0; i < arity; ++i) {
871 ir_node *pred = get_Block_cfgpred_block(block, i);
872 workset_t *pred_end_workset = get_block_info(pred)->end_workset;
875 DB((dbg, DBG_FIX, " Pred %+F\n", pred));
877 /* spill all values not used anymore */
878 workset_foreach(pred_end_workset, node, iter) {
882 workset_foreach(start_workset, n2, iter2) {
887 /* note that we do not look at phi inputs, becuase the values
888 * will be either live-end and need no spill or
889 * they have other users in which must be somewhere else in the
896 if (move_spills && be_is_live_in(lv, block, node)
897 && !pred_end_workset->vals[iter].spilled) {
898 ir_node *insert_point;
900 insert_point = be_get_end_of_block_insertion_point(pred);
901 insert_point = sched_prev(insert_point);
903 insert_point = block;
905 DB((dbg, DBG_SPILL, "Spill %+F after %+F\n", node,
907 be_add_spill(senv, node, insert_point);
911 /* reload missing values in predecessors, add missing spills */
912 workset_foreach(start_workset, node, iter) {
913 const loc_t *l = &start_workset->vals[iter];
914 const loc_t *pred_loc;
916 /* if node is a phi of the current block we reload
917 * the corresponding argument, else node itself */
918 if (is_Phi(node) && get_nodes_block(node) == block) {
919 node = get_irn_n(node, i);
922 /* we might have unknowns as argument for the phi */
923 if (!arch_irn_consider_in_reg_alloc(cls, node))
927 /* check if node is in a register at end of pred */
928 pred_loc = workset_contains(pred_end_workset, node);
929 if (pred_loc != NULL) {
930 /* we might have to spill value on this path */
931 if (move_spills && !pred_loc->spilled && l->spilled) {
932 ir_node *insert_point
933 = be_get_end_of_block_insertion_point(pred);
934 insert_point = sched_prev(insert_point);
935 DB((dbg, DBG_SPILL, "Spill %+F after %+F\n", node,
937 be_add_spill(senv, node, insert_point);
940 /* node is not in register at the end of pred -> reload it */
941 DB((dbg, DBG_FIX, " reload %+F\n", node));
942 DB((dbg, DBG_SPILL, "Reload %+F before %+F,%d\n", node, block, i));
943 be_add_reload_on_edge(senv, node, block, i, cls, 1);
949 static void be_spill_belady(ir_graph *irg, const arch_register_class_t *rcls)
953 be_liveness_assure_sets(be_assure_liveness(irg));
956 /* construct control flow loop tree */
957 if (! (get_irg_loopinfo_state(irg) & loopinfo_cf_consistent)) {
958 construct_cf_backedges(irg);
960 stat_ev_tim_pop("belady_time_backedges");
964 stat_ev_tim_pop("belady_time_clear_links");
966 ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
968 /* init belady env */
972 lv = be_get_irg_liveness(irg);
973 n_regs = cls->n_regs - be_put_ignore_regs(irg, cls, NULL);
975 uses = be_begin_uses(irg, lv);
976 loop_ana = be_new_loop_pressure(irg, cls);
977 senv = be_new_spill_env(irg);
978 blocklist = be_get_cfgpostorder(irg);
979 stat_ev_tim_pop("belady_time_init");
982 /* walk blocks in reverse postorder */
983 for (i = ARR_LEN(blocklist) - 1; i >= 0; --i) {
984 process_block(blocklist[i]);
986 DEL_ARR_F(blocklist);
987 stat_ev_tim_pop("belady_time_belady");
990 /* belady was block-local, fix the global flow by adding reloads on the
992 irg_block_walk_graph(irg, fix_block_borders, NULL, NULL);
993 stat_ev_tim_pop("belady_time_fix_borders");
995 ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
997 /* Insert spill/reload nodes into the graph and fix usages */
998 be_insert_spills_reloads(senv);
1001 be_delete_spill_env(senv);
1003 be_free_loop_pressure(loop_ana);
1004 obstack_free(&obst, NULL);
1007 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillbelady);
1008 void be_init_spillbelady(void)
1010 static be_spiller_t belady_spiller = {
1013 lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
1014 lc_opt_entry_t *belady_group = lc_opt_get_grp(be_grp, "belady");
1015 lc_opt_add_table(belady_group, options);
1017 be_register_spiller("belady", &belady_spiller);
1018 FIRM_DBG_REGISTER(dbg, "firm.be.spill.belady");