X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbespillbelady.c;h=962d1c3a156bd146cfa05a78665b4ebb2d634385;hb=a09efb2ccc91c6d720aa6aa8c5f7e3c562528b2a;hp=565af05b6d9bbe08ac210aacf6407f0b3bcbfda9;hpb=8a40be4492274e2799181e4ce950b33b367a59ef;p=libfirm diff --git a/ir/be/bespillbelady.c b/ir/be/bespillbelady.c index 565af05b6..962d1c3a1 100644 --- a/ir/be/bespillbelady.c +++ b/ir/be/bespillbelady.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -75,7 +75,7 @@ typedef struct loc_t { bool spilled; /**< value was already spilled on this path */ } loc_t; -typedef struct _workset_t { +typedef struct workset_t { unsigned len; /**< current length */ loc_t vals[0]; /**< array of the values/distances in this working set */ } workset_t; @@ -89,8 +89,6 @@ 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; @@ -213,8 +211,8 @@ static const loc_t *workset_contains(const workset_t *ws, const ir_node *val) static int loc_compare(const void *a, const void *b) { - const loc_t *p = a; - const loc_t *q = b; + const loc_t *p = (const loc_t*)a; + const loc_t *q = (const loc_t*)b; return p->time - q->time; } @@ -255,11 +253,10 @@ 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 */ -#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 -{ +typedef struct block_info_t { workset_t *start_workset; workset_t *end_workset; } block_info_t; @@ -271,7 +268,7 @@ static block_info_t *new_block_info(void) 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) @@ -282,8 +279,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 */ -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; @@ -291,7 +287,7 @@ static unsigned get_distance(ir_node *from, unsigned from_step, 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; @@ -366,7 +362,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); - unsigned dist = get_distance(instr, instr_nr, val, !is_usage); + unsigned dist = get_distance(instr, val, !is_usage); workset_set_time(ws, i, dist); } @@ -489,7 +485,7 @@ static loc_t to_take_or_not_to_take(ir_node* first, ir_node *node, 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)); @@ -543,7 +539,7 @@ static void decide_start_workset(const ir_node *block) unsigned i; int in; unsigned ws_count; - int free_slots, free_pressure_slots; + int free_slots, free_pressure_slots; unsigned pressure; int arity; workset_t **pred_worksets; @@ -621,7 +617,7 @@ static void decide_start_workset(const ir_node *block) } 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); @@ -632,7 +628,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) { - 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) { @@ -796,7 +793,6 @@ static void process_block(ir_node *block) /* 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(); @@ -833,8 +829,6 @@ static void process_block(ir_node *block) workset_insert(new_vals, value, false); ); displace(new_vals, 0); - - instr_nr++; } /* Remember end-workset for this block */ @@ -971,7 +965,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); - 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);