projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cleanup: Fix typos in comments.
[libfirm]
/
ir
/
be
/
bespillbelady.c
diff --git
a/ir/be/bespillbelady.c
b/ir/be/bespillbelady.c
index
dcf4eab
..
ad654a7
100644
(file)
--- a/
ir/be/bespillbelady.c
+++ b/
ir/be/bespillbelady.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 1995-20
08
University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-20
11
University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
*
* This file is part of libFirm.
*
@@
-22,14
+22,12
@@
* @brief Beladys spillalgorithm.
* @author Daniel Grund, Matthias Braun
* @date 20.09.2005
* @brief Beladys spillalgorithm.
* @author Daniel Grund, Matthias Braun
* @date 20.09.2005
- * @version $Id$
*/
#include "config.h"
#include <stdbool.h>
#include "obst.h"
*/
#include "config.h"
#include <stdbool.h>
#include "obst.h"
-#include "irprintf_t.h"
#include "irgraph.h"
#include "irnode.h"
#include "irmode.h"
#include "irgraph.h"
#include "irnode.h"
#include "irmode.h"
@@
-39,6
+37,9
@@
#include "ircons_t.h"
#include "irprintf.h"
#include "irnodeset.h"
#include "ircons_t.h"
#include "irprintf.h"
#include "irnodeset.h"
+#include "irtools.h"
+#include "statev_t.h"
+#include "util.h"
#include "beutil.h"
#include "bearch.h"
#include "beutil.h"
#include "bearch.h"
@@
-77,7
+78,7
@@
typedef struct loc_t {
typedef struct workset_t {
unsigned len; /**< current length */
typedef struct workset_t {
unsigned len; /**< current length */
- loc_t vals[
0];
/**< array of the values/distances in this working set */
+ loc_t vals[
];
/**< array of the values/distances in this working set */
} workset_t;
static struct obstack obst;
} workset_t;
static struct obstack obst;
@@
-88,9
+89,6
@@
static unsigned n_regs;
static workset_t *ws; /**< the main workset used while
processing a block. */
static be_uses_t *uses; /**< env for the next-use magic */
static workset_t *ws; /**< the main workset used while
processing a block. */
static be_uses_t *uses; /**< env for the next-use magic */
-static ir_node *instr; /**< current instruction */
-static unsigned instr_nr; /**< current instruction number
- (relative to block start) */
static spill_env_t *senv; /**< see bespill.h */
static ir_node **blocklist;
static spill_env_t *senv; /**< see bespill.h */
static ir_node **blocklist;
@@
-213,9
+211,17
@@
static const loc_t *workset_contains(const workset_t *ws, const ir_node *val)
static int loc_compare(const void *a, const void *b)
{
static int loc_compare(const void *a, const void *b)
{
- const loc_t *p = a;
- const loc_t *q = b;
- return p->time - q->time;
+ const loc_t *p = ((const loc_t*) a);
+ const loc_t *q = ((const loc_t*) b);
+ const unsigned pt = p->time;
+ const unsigned qt = q->time;
+
+ if (pt < qt)
+ return -1;
+ if (pt > qt)
+ return 1;
+
+ return get_irn_node_nr(p->node) - get_irn_node_nr(q->node);
}
static void workset_sort(workset_t *workset)
}
static void workset_sort(workset_t *workset)
@@
-255,7
+261,7
@@
static inline ir_node *workset_get_val(const workset_t *workset, unsigned idx)
* @p v A variable to put the current value in
* @p i An integer for internal use
*/
* @p v A variable to put the current value in
* @p i An integer for internal use
*/
-#define workset_foreach(ws, v, i)
\
+#define workset_foreach(ws, v, i) \
for (i=0; v=(i < ws->len) ? ws->vals[i].node : NULL, i < ws->len; ++i)
typedef struct block_info_t {
for (i=0; v=(i < ws->len) ? ws->vals[i].node : NULL, i < ws->len; ++i)
typedef struct block_info_t {
@@
-270,7
+276,7
@@
static block_info_t *new_block_info(void)
static inline block_info_t *get_block_info(const ir_node *block)
{
static inline block_info_t *get_block_info(const ir_node *block)
{
- return get_irn_link(block);
+ return
(block_info_t*)
get_irn_link(block);
}
static inline void set_block_info(ir_node *block, block_info_t *info)
}
static inline void set_block_info(ir_node *block, block_info_t *info)
@@
-281,8
+287,7
@@
static inline void set_block_info(ir_node *block, block_info_t *info)
/**
* @return The distance to the next use or 0 if irn has dont_spill flag set
*/
/**
* @return The distance to the next use or 0 if irn has dont_spill flag set
*/
-static unsigned get_distance(ir_node *from, unsigned from_step,
- const ir_node *def, int skip_from_uses)
+static unsigned get_distance(ir_node *from, const ir_node *def, int skip_from_uses)
{
be_next_use_t use;
unsigned costs;
{
be_next_use_t use;
unsigned costs;
@@
-290,13
+295,13
@@
static unsigned get_distance(ir_node *from, unsigned from_step,
assert(!arch_irn_is_ignore(def));
assert(!arch_irn_is_ignore(def));
- use = be_get_next_use(uses, from,
from_step,
def, skip_from_uses);
+ use = be_get_next_use(uses, from, def, skip_from_uses);
time = use.time;
if (USES_IS_INFINITE(time))
return USES_INFINITY;
/* We have to keep nonspillable nodes in the workingset */
time = use.time;
if (USES_IS_INFINITE(time))
return USES_INFINITY;
/* We have to keep nonspillable nodes in the workingset */
- if (arch_
irn_get
_flags(skip_Proj_const(def)) & arch_irn_flags_dont_spill)
+ if (arch_
get_irn
_flags(skip_Proj_const(def)) & arch_irn_flags_dont_spill)
return 0;
/* give some bonus to rematerialisable nodes */
return 0;
/* give some bonus to rematerialisable nodes */
@@
-318,7
+323,7
@@
static unsigned get_distance(ir_node *from, unsigned from_step,
* @p is_usage indicates that the values in new_vals are used (not defined)
* In this case reloads must be performed
*/
* @p is_usage indicates that the values in new_vals are used (not defined)
* In this case reloads must be performed
*/
-static void displace(workset_t *
new_vals, int is_usage
)
+static void displace(workset_t *
const new_vals, int const is_usage, ir_node *const instr
)
{
ir_node **to_insert = ALLOCAN(ir_node*, n_regs);
bool *spilled = ALLOCAN(bool, n_regs);
{
ir_node **to_insert = ALLOCAN(ir_node*, n_regs);
bool *spilled = ALLOCAN(bool, n_regs);
@@
-365,7
+370,7
@@
static void displace(workset_t *new_vals, int is_usage)
/* calculate current next-use distance for live values */
for (i = 0; i < len; ++i) {
ir_node *val = workset_get_val(ws, i);
/* calculate current next-use distance for live values */
for (i = 0; i < len; ++i) {
ir_node *val = workset_get_val(ws, i);
- unsigned dist = get_distance(instr,
instr_nr,
val, !is_usage);
+ unsigned dist = get_distance(instr, val, !is_usage);
workset_set_time(ws, i, dist);
}
workset_set_time(ws, i, dist);
}
@@
-476,19
+481,14
@@
static loc_t to_take_or_not_to_take(ir_node* first, ir_node *node,
loc.node = node;
loc.spilled = false;
loc.node = node;
loc.spilled = false;
- if (!arch_irn_consider_in_reg_alloc(cls, node)) {
- loc.time = USES_INFINITY;
- return loc;
- }
-
/* We have to keep nonspillable nodes in the workingset */
/* We have to keep nonspillable nodes in the workingset */
- if (arch_
irn_get
_flags(skip_Proj_const(node)) & arch_irn_flags_dont_spill) {
+ if (arch_
get_irn
_flags(skip_Proj_const(node)) & arch_irn_flags_dont_spill) {
loc.time = 0;
DB((dbg, DBG_START, " %+F taken (dontspill node)\n", node, loc.time));
return loc;
}
loc.time = 0;
DB((dbg, DBG_START, " %+F taken (dontspill node)\n", node, loc.time));
return loc;
}
- next_use = be_get_next_use(uses, first,
0,
node, 0);
+ next_use = be_get_next_use(uses, first, node, 0);
if (USES_IS_INFINITE(next_use.time)) {
/* the nodes marked as live in shouldn't be dead, so it must be a phi */
assert(is_Phi(node));
if (USES_IS_INFINITE(next_use.time)) {
/* the nodes marked as live in shouldn't be dead, so it must be a phi */
assert(is_Phi(node));
@@
-534,15
+534,13
@@
static void decide_start_workset(const ir_node *block)
{
ir_loop *loop = get_irn_loop(block);
ir_node *first;
{
ir_loop *loop = get_irn_loop(block);
ir_node *first;
- ir_node *node;
loc_t loc;
loc_t *starters;
loc_t *delayed;
unsigned len;
unsigned i;
loc_t loc;
loc_t *starters;
loc_t *delayed;
unsigned len;
unsigned i;
- int in;
unsigned ws_count;
unsigned ws_count;
- int
free_slots, free_pressure_slots;
+ int free_slots, free_pressure_slots;
unsigned pressure;
int arity;
workset_t **pred_worksets;
unsigned pressure;
int arity;
workset_t **pred_worksets;
@@
-552,7
+550,7
@@
static void decide_start_workset(const ir_node *block)
arity = get_irn_arity(block);
pred_worksets = ALLOCAN(workset_t*, arity);
all_preds_known = true;
arity = get_irn_arity(block);
pred_worksets = ALLOCAN(workset_t*, arity);
all_preds_known = true;
- for (in = 0; in < arity; ++in) {
+ for (in
t in
= 0; in < arity; ++in) {
ir_node *pred_block = get_Block_cfgpred_block(block, in);
block_info_t *pred_info = get_block_info(pred_block);
ir_node *pred_block = get_Block_cfgpred_block(block, in);
block_info_t *pred_info = get_block_info(pred_block);
@@
-599,10
+597,8
@@
static void decide_start_workset(const ir_node *block)
}
/* check all Live-Ins */
}
/* check all Live-Ins */
- be_lv_foreach(lv, block, be_lv_state_in, in) {
- ir_node *node = be_lv_get_irn(lv, block, in);
+ be_lv_foreach_cls(lv, block, be_lv_state_in, cls, node) {
unsigned available;
unsigned available;
-
if (all_preds_known) {
available = available_in_all_preds(pred_worksets, arity, node, false);
} else {
if (all_preds_known) {
available = available_in_all_preds(pred_worksets, arity, node, false);
} else {
@@
-620,7
+616,7
@@
static void decide_start_workset(const ir_node *block)
}
pressure = be_get_loop_pressure(loop_ana, cls, loop);
}
pressure = be_get_loop_pressure(loop_ana, cls, loop);
- assert(ARR_LEN(delayed) <=
(signed)
pressure);
+ assert(ARR_LEN(delayed) <= pressure);
free_slots = n_regs - ARR_LEN(starters);
free_pressure_slots = n_regs - (pressure - ARR_LEN(delayed));
free_slots = MIN(free_slots, free_pressure_slots);
free_slots = n_regs - ARR_LEN(starters);
free_pressure_slots = n_regs - (pressure - ARR_LEN(delayed));
free_slots = MIN(free_slots, free_pressure_slots);
@@
-631,7
+627,8
@@
static void decide_start_workset(const ir_node *block)
DB((dbg, DBG_START, "Loop pressure %d, taking %d delayed vals\n",
pressure, free_slots));
if (free_slots > 0) {
DB((dbg, DBG_START, "Loop pressure %d, taking %d delayed vals\n",
pressure, free_slots));
if (free_slots > 0) {
- int i;
+ size_t i;
+
qsort(delayed, ARR_LEN(delayed), sizeof(delayed[0]), loc_compare);
for (i = 0; i < ARR_LEN(delayed) && free_slots > 0; ++i) {
qsort(delayed, ARR_LEN(delayed), sizeof(delayed[0]), loc_compare);
for (i = 0; i < ARR_LEN(delayed) && free_slots > 0; ++i) {
@@
-754,7
+751,6
@@
static void decide_start_workset(const ir_node *block)
static void process_block(ir_node *block)
{
workset_t *new_vals;
static void process_block(ir_node *block)
{
workset_t *new_vals;
- ir_node *irn;
unsigned iter;
block_info_t *block_info;
int arity;
unsigned iter;
block_info_t *block_info;
int arity;
@@
-768,7
+764,7
@@
static void process_block(ir_node *block)
/* no predecessor -> empty set */
workset_clear(ws);
} else if (arity == 1) {
/* no predecessor -> empty set */
workset_clear(ws);
} else if (arity == 1) {
- /* one predecessor, copy it
'
s end workset */
+ /* one predecessor, copy its end workset */
ir_node *pred_block = get_Block_cfgpred_block(block, 0);
block_info_t *pred_info = get_block_info(pred_block);
ir_node *pred_block = get_Block_cfgpred_block(block, 0);
block_info_t *pred_info = get_block_info(pred_block);
@@
-786,22
+782,21
@@
static void process_block(ir_node *block)
set_block_info(block, block_info);
DB((dbg, DBG_WSETS, "Start workset for %+F:\n", block));
set_block_info(block, block_info);
DB((dbg, DBG_WSETS, "Start workset for %+F:\n", block));
- workset_foreach(ws, irn, iter) {
- DB((dbg, DBG_WSETS, " %+F (%u)\n", irn,
- workset_get_time(ws, iter)));
+ {
+ ir_node *irn;
+ workset_foreach(ws, irn, iter) {
+ DB((dbg, DBG_WSETS, " %+F (%u)\n", irn, workset_get_time(ws, iter)));
+ }
}
block_info->start_workset = workset_clone(ws);
/* process the block from start to end */
DB((dbg, DBG_WSETS, "Processing...\n"));
}
block_info->start_workset = workset_clone(ws);
/* process the block from start to end */
DB((dbg, DBG_WSETS, "Processing...\n"));
- instr_nr = 0;
/* TODO: this leaks (into the obstack)... */
new_vals = new_workset();
sched_foreach(block, irn) {
/* TODO: this leaks (into the obstack)... */
new_vals = new_workset();
sched_foreach(block, irn) {
- int i, arity;
- ir_node *value;
assert(workset_get_length(ws) <= n_regs);
/* Phis are no real instr (see insert_starters()) */
assert(workset_get_length(ws) <= n_regs);
/* Phis are no real instr (see insert_starters()) */
@@
-810,37
+805,31
@@
static void process_block(ir_node *block)
}
DB((dbg, DBG_DECIDE, " ...%+F\n", irn));
}
DB((dbg, DBG_DECIDE, " ...%+F\n", irn));
- /* set instruction in the workset */
- instr = irn;
-
/* allocate all values _used_ by this instruction */
workset_clear(new_vals);
/* allocate all values _used_ by this instruction */
workset_clear(new_vals);
- for (i = 0, arity = get_irn_arity(irn); i < arity; ++i) {
- ir_node *in = get_irn_n(irn, i);
- if (!arch_irn_consider_in_reg_alloc(cls, in))
- continue;
-
+ be_foreach_use(irn, cls, in_req_, in, in_req,
/* (note that "spilled" is irrelevant here) */
workset_insert(new_vals, in, false);
/* (note that "spilled" is irrelevant here) */
workset_insert(new_vals, in, false);
- }
- displace(new_vals, 1);
+ );
+ displace(new_vals, 1
, irn
);
/* allocate all values _defined_ by this instruction */
workset_clear(new_vals);
/* allocate all values _defined_ by this instruction */
workset_clear(new_vals);
- be_foreach_definition(irn, cls, value,
- assert(req
_
->width == 1);
+ be_foreach_definition(irn, cls, value,
req,
+ assert(req->width == 1);
workset_insert(new_vals, value, false);
);
workset_insert(new_vals, value, false);
);
- displace(new_vals, 0);
-
- instr_nr++;
+ displace(new_vals, 0, irn);
}
/* Remember end-workset for this block */
block_info->end_workset = workset_clone(ws);
DB((dbg, DBG_WSETS, "End workset for %+F:\n", block));
}
/* Remember end-workset for this block */
block_info->end_workset = workset_clone(ws);
DB((dbg, DBG_WSETS, "End workset for %+F:\n", block));
- workset_foreach(ws, irn, iter)
- DB((dbg, DBG_WSETS, " %+F (%u)\n", irn, workset_get_time(ws, iter)));
+ {
+ ir_node *irn;
+ workset_foreach(ws, irn, iter)
+ DB((dbg, DBG_WSETS, " %+F (%u)\n", irn, workset_get_time(ws, iter)));
+ }
}
/**
}
/**
@@
-950,13
+939,10
@@
static void be_spill_belady(ir_graph *irg, const arch_register_class_t *rcls)
{
int i;
{
int i;
- be_
liveness_assure_sets(be_assure_liveness(irg)
);
+ be_
assure_live_sets(irg
);
stat_ev_tim_push();
stat_ev_tim_push();
- /* construct control flow loop tree */
- if (! (get_irg_loopinfo_state(irg) & loopinfo_cf_consistent)) {
- construct_cf_backedges(irg);
- }
+ assure_loopinfo(irg);
stat_ev_tim_pop("belady_time_backedges");
stat_ev_tim_push();
stat_ev_tim_pop("belady_time_backedges");
stat_ev_tim_push();
@@
-970,7
+956,7
@@
static void be_spill_belady(ir_graph *irg, const arch_register_class_t *rcls)
obstack_init(&obst);
cls = rcls;
lv = be_get_irg_liveness(irg);
obstack_init(&obst);
cls = rcls;
lv = be_get_irg_liveness(irg);
- n_regs =
cls->n_regs - be_put_ignore_regs(irg, cls, NULL
);
+ n_regs =
be_get_n_allocatable_regs(irg, cls
);
ws = new_workset();
uses = be_begin_uses(irg, lv);
loop_ana = be_new_loop_pressure(irg, cls);
ws = new_workset();
uses = be_begin_uses(irg, lv);
loop_ana = be_new_loop_pressure(irg, cls);
@@
-1004,7
+990,7
@@
static void be_spill_belady(ir_graph *irg, const arch_register_class_t *rcls)
obstack_free(&obst, NULL);
}
obstack_free(&obst, NULL);
}
-BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillbelady)
;
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillbelady)
void be_init_spillbelady(void)
{
static be_spiller_t belady_spiller = {
void be_init_spillbelady(void)
{
static be_spiller_t belady_spiller = {