Commit 05401c2c authored by Matthias Braun's avatar Matthias Braun
Browse files

simplify by using C99

parent 8c1ce44e
......@@ -116,8 +116,8 @@ static void spill_node(ir_node *node)
continue;
if (is_Phi(use)) {
int in = get_edge_src_pos(edge);
ir_node *block = get_nodes_block(use);
int in = get_edge_src_pos(edge);
ir_node *block = get_nodes_block(use);
be_add_reload_on_edge(spill_env, node, block, in, cls, 1);
} else {
......@@ -140,24 +140,17 @@ static unsigned get_value_width(const ir_node *node)
*/
static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
{
size_t n_live_nodes = ir_nodeset_size(live_nodes);
size_t values_defined = 0;
size_t free_regs_needed = 0;
spill_candidate_t *candidates;
int i, arity;
size_t c;
int spills_needed;
size_t cand_idx;
ir_node *value;
size_t values_defined = 0;
ir_node *value;
be_foreach_definition(node, cls, value,
assert(req_->width >= 1);
values_defined += req_->width;
);
/* we need registers for the non-live argument values */
arity = get_irn_arity(node);
for (i = 0; i < arity; ++i) {
size_t free_regs_needed = 0;
int arity = get_irn_arity(node);
for (int i = 0; i < arity; ++i) {
ir_node *pred = get_irn_n(node, i);
if (arch_irn_consider_in_reg_alloc(cls, pred)
&& !ir_nodeset_contains(live_nodes, pred)) {
......@@ -170,15 +163,16 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
if (values_defined > free_regs_needed)
free_regs_needed = values_defined;
spills_needed = (n_live_nodes + free_regs_needed) - n_regs;
size_t n_live_nodes = ir_nodeset_size(live_nodes);
int spills_needed = (n_live_nodes + free_regs_needed) - n_regs;
if (spills_needed <= 0)
return;
DBG((dbg, LEVEL_2, "\tspills needed after %+F: %d\n", node, spills_needed));
candidates = ALLOCAN(spill_candidate_t, n_live_nodes);
spill_candidate_t *candidates = ALLOCAN(spill_candidate_t, n_live_nodes);
/* construct array with spill candidates and calculate their costs */
c = 0;
size_t c = 0;
foreach_ir_nodeset(live_nodes, n, iter) {
spill_candidate_t *candidate = & candidates[c];
......@@ -195,25 +189,22 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
compare_spill_candidates_desc);
/* spill cheapest ones */
cand_idx = 0;
size_t cand_idx = 0;
while (spills_needed > 0) {
bool is_use = false;
spill_candidate_t *candidate;
ir_node *cand_node;
if (cand_idx >= n_live_nodes) {
panic("can't spill enough values for node %+F", node);
}
candidate = &candidates[cand_idx];
cand_node = candidate->node;
spill_candidate_t *candidate = &candidates[cand_idx];
ir_node *cand_node = candidate->node;
++cand_idx;
if (arch_irn_is(skip_Proj_const(cand_node), dont_spill))
continue;
/* make sure the node is not an argument of the instruction */
for (i = 0; i < arity; ++i) {
bool is_use = false;
for (int i = 0; i < arity; ++i) {
ir_node *in = get_irn_n(node, i);
if (in == cand_node) {
is_use = true;
......@@ -234,10 +225,10 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node)
*/
static void remove_defs(ir_node *node, ir_nodeset_t *nodeset)
{
ir_node *value;
/* You must break out of your loop when hitting the first phi function. */
assert(!is_Phi(node));
ir_node *value;
be_foreach_definition(node, cls, value,
ir_nodeset_remove(nodeset, value);
);
......@@ -245,10 +236,8 @@ static void remove_defs(ir_node *node, ir_nodeset_t *nodeset)
static void add_uses(ir_node *node, ir_nodeset_t *nodeset)
{
int i, arity;
arity = get_irn_arity(node);
for (i = 0; i < arity; ++i) {
int arity = get_irn_arity(node);
for (int i = 0; i < arity; ++i) {
ir_node *op = get_irn_n(node, i);
if (arch_irn_consider_in_reg_alloc(cls, op) &&
......@@ -273,16 +262,11 @@ void print_nodeset(ir_nodeset_t *nodeset)
*/
static void spill_block(ir_node *block, void *data)
{
ir_nodeset_t live_nodes;
int n_phi_values_spilled;
int regpressure;
int live_nodes_pressure;
int phi_spills_needed;
(void) data;
DBG((dbg, LEVEL_1, "spilling block %+F\n", block));
/* construct set of live nodes at end of block */
ir_nodeset_t live_nodes;
ir_nodeset_init(&live_nodes);
be_liveness_end_of_block(lv, cls, block, &live_nodes);
......@@ -311,7 +295,7 @@ static void spill_block(ir_node *block, void *data)
/* until now only the values of some phis have been spilled the phis itself
* are still there and occupy registers, so we need to count them and might
* have to spill some of them. */
n_phi_values_spilled = 0;
int n_phi_values_spilled = 0;
sched_foreach(block, node) {
if (!is_Phi(node))
break;
......@@ -321,14 +305,14 @@ static void spill_block(ir_node *block, void *data)
}
}
live_nodes_pressure = 0;
int live_nodes_pressure = 0;
foreach_ir_nodeset(&live_nodes, node, iter) {
live_nodes_pressure += get_value_width(node);
}
/* calculate how many of the phis need to be spilled */
regpressure = live_nodes_pressure + n_phi_values_spilled;
phi_spills_needed = regpressure - n_regs;
int regpressure = live_nodes_pressure + n_phi_values_spilled;
int phi_spills_needed = regpressure - n_regs;
DBG((dbg, LEVEL_3, "Regpressure before phis: %d phispills: %d\n",
regpressure, phi_spills_needed));
......
......@@ -57,8 +57,6 @@ static be_transform_env_t env;
void be_set_transformed_node(ir_node *old_node, ir_node *new_node)
{
ir_graph *irg = get_irn_irg(old_node);
set_irn_link(old_node, new_node);
mark_irn_visited(old_node);
hook_dead_node_elim_subst(irg, old_node, new_node);
......@@ -81,10 +79,8 @@ static inline ir_node *be_get_transformed_node(ir_node *old_node)
void be_duplicate_deps(ir_node *old_node, ir_node *new_node)
{
int i;
int deps = get_irn_deps(old_node);
for (i = 0; i < deps; ++i) {
for (int i = 0; i < deps; ++i) {
ir_node *dep = get_irn_dep(old_node, i);
ir_node *new_dep = be_transform_node(dep);
......@@ -106,12 +102,11 @@ void be_set_transform_function(ir_op *op, be_transform_func func)
*/
static ir_node *transform_block(ir_node *node)
{
ir_graph *irg = get_irn_irg(node);
dbg_info *dbgi = get_irn_dbg_info(node);
ir_node *block;
block = new_ir_node(dbgi, irg, NULL, get_irn_op(node), get_irn_mode(node),
get_irn_arity(node), get_irn_in(node) + 1);
ir_graph *irg = get_irn_irg(node);
dbg_info *dbgi = get_irn_dbg_info(node);
ir_mode *mode = get_irn_mode(node);
ir_node *block = new_ir_node(dbgi, irg, NULL, get_irn_op(node), mode,
get_irn_arity(node), get_irn_in(node) + 1);
copy_node_attr(irg, node, block);
block->node_nr = node->node_nr;
......@@ -128,13 +123,10 @@ static ir_node *transform_block(ir_node *node)
static ir_node *transform_end(ir_node *node)
{
/* end has to be duplicated manually because we need a dynamic in array */
ir_graph *irg = get_irn_irg(node);
dbg_info *dbgi = get_irn_dbg_info(node);
ir_node *block = be_transform_node(get_nodes_block(node));
int i, arity;
ir_node *new_end;
new_end = new_ir_node(dbgi, irg, block, op_End, mode_X, -1, NULL);
ir_graph *irg = get_irn_irg(node);
dbg_info *dbgi = get_irn_dbg_info(node);
ir_node *block = be_transform_node(get_nodes_block(node));
ir_node *new_end = new_ir_node(dbgi, irg, block, op_End, mode_X, -1, NULL);
copy_node_attr(irg, node, new_end);
be_duplicate_deps(node, new_end);
......@@ -142,8 +134,8 @@ static ir_node *transform_end(ir_node *node)
/* do not transform predecessors yet to keep the pre-transform
* phase from visiting all the graph */
arity = get_irn_arity(node);
for (i = 0; i < arity; ++i) {
int arity = get_irn_arity(node);
for (int i = 0; i < arity; ++i) {
ir_node *in = get_irn_n(node, i);
add_End_keepalive(new_end, in);
}
......@@ -178,20 +170,19 @@ ir_node *be_duplicate_node(ir_node *node)
dbg_info *dbgi = get_irn_dbg_info(node);
ir_mode *mode = get_irn_mode(node);
ir_op *op = get_irn_op(node);
ir_node *new_node;
int i, arity;
arity = get_irn_arity(node);
ir_node *new_node;
int arity = get_irn_arity(node);
if (op->opar == oparity_dynamic) {
new_node = new_ir_node(dbgi, irg, block, op, mode, -1, NULL);
for (i = 0; i < arity; ++i) {
for (int i = 0; i < arity; ++i) {
ir_node *in = get_irn_n(node, i);
in = be_transform_node(in);
add_irn_n(new_node, in);
}
} else {
ir_node **ins = ALLOCAN(ir_node*, arity);
for (i = 0; i < arity; ++i) {
for (int i = 0; i < arity; ++i) {
ir_node *in = get_irn_n(node, i);
ins[i] = be_transform_node(in);
}
......@@ -208,20 +199,17 @@ ir_node *be_duplicate_node(ir_node *node)
ir_node *be_transform_node(ir_node *node)
{
ir_op *op;
ir_node *new_node = be_get_transformed_node(node);
be_transform_func *transform;
ir_node *new_node = be_get_transformed_node(node);
if (new_node != NULL)
return new_node;
DEBUG_ONLY(be_set_transformed_node(node, NULL);)
op = get_irn_op(node);
ir_op *op = get_irn_op(node);
if (op->ops.generic == NULL) {
panic("No transform function registered for node %+F.", node);
}
transform = (be_transform_func *)op->ops.generic;
be_transform_func *transform = (be_transform_func *)op->ops.generic;
new_node = transform(node);
assert(new_node != NULL);
......@@ -232,11 +220,9 @@ ir_node *be_transform_node(ir_node *node)
void be_enqueue_preds(ir_node *node)
{
int i, arity;
/* put the preds in the worklist */
arity = get_irn_arity(node);
for (i = 0; i < arity; ++i) {
int arity = get_irn_arity(node);
for (int i = 0; i < arity; ++i) {
ir_node *pred = get_irn_n(node, i);
pdeq_putr(env.worklist, pred);
}
......@@ -247,15 +233,12 @@ void be_enqueue_preds(ir_node *node)
*/
static void fix_loops(ir_node *node)
{
int i, arity;
int changed;
assert(node_is_in_irgs_storage(env.irg, node));
if (irn_visited_else_mark(node))
return;
changed = 0;
bool changed = false;
if (! is_Block(node)) {
ir_node *block = get_nodes_block(node);
ir_node *new_block = (ir_node*)get_irn_link(block);
......@@ -263,21 +246,21 @@ static void fix_loops(ir_node *node)
if (new_block != NULL) {
set_nodes_block(node, new_block);
block = new_block;
changed = 1;
changed = true;
}
fix_loops(block);
}
arity = get_irn_arity(node);
for (i = 0; i < arity; ++i) {
int arity = get_irn_arity(node);
for (int i = 0; i < arity; ++i) {
ir_node *in = get_irn_n(node, i);
ir_node *nw = (ir_node*)get_irn_link(in);
if (nw != NULL && nw != in) {
set_irn_n(node, i, nw);
in = nw;
changed = 1;
changed = true;
}
fix_loops(in);
......@@ -285,18 +268,18 @@ static void fix_loops(ir_node *node)
/* fix proj block */
if (is_Proj(node)) {
set_nodes_block(node, get_nodes_block(get_Proj_pred(node)));
changed = 1;
changed = true;
}
arity = get_irn_deps(node);
for (i = 0; i < arity; ++i) {
for (int i = 0; i < arity; ++i) {
ir_node *in = get_irn_dep(node, i);
ir_node *nw = (ir_node*)get_irn_link(in);
if (nw != NULL && nw != in) {
set_irn_dep(node, i, nw);
in = nw;
changed = 1;
changed = true;
}
fix_loops(in);
......@@ -327,9 +310,6 @@ static void pre_transform_anchor(ir_graph *irg, int anchor)
*/
static void transform_nodes(ir_graph *irg, arch_pretrans_nodes *pre_transform)
{
int i;
ir_node *old_end, *new_anchor;
hook_dead_node_elim(irg, 1);
inc_irg_visited(irg);
......@@ -338,10 +318,10 @@ static void transform_nodes(ir_graph *irg, arch_pretrans_nodes *pre_transform)
env.worklist = new_waitq();
env.old_anchor = irg->anchor;
old_end = get_irg_end(irg);
ir_node *old_end = get_irg_end(irg);
/* put all anchor nodes in the worklist */
for (i = get_irg_n_anchors(irg) - 1; i >= 0; --i) {
for (int i = get_irg_n_anchors(irg) - 1; i >= 0; --i) {
ir_node *anchor = get_irg_anchor(irg, i);
if (anchor == NULL)
......@@ -349,7 +329,7 @@ static void transform_nodes(ir_graph *irg, arch_pretrans_nodes *pre_transform)
waitq_put(env.worklist, anchor);
}
new_anchor = new_r_Anchor(irg);
ir_node *new_anchor = new_r_Anchor(irg);
irg->anchor = new_anchor;
/* pre transform some anchors (so they are available in the other transform
......@@ -372,7 +352,7 @@ static void transform_nodes(ir_graph *irg, arch_pretrans_nodes *pre_transform)
/* fix loops and set new anchors*/
inc_irg_visited(irg);
for (i = get_irg_n_anchors(irg) - 1; i >= 0; --i) {
for (int i = get_irg_n_anchors(irg) - 1; i >= 0; --i) {
ir_node *anchor = get_irn_n(env.old_anchor, i);
if (anchor == NULL)
......@@ -391,14 +371,11 @@ static void transform_nodes(ir_graph *irg, arch_pretrans_nodes *pre_transform)
void be_transform_graph(ir_graph *irg, arch_pretrans_nodes *func)
{
ir_graph *old_current_ir_graph = current_ir_graph;
struct obstack *old_obst = NULL;
struct obstack *new_obst = NULL;
current_ir_graph = irg;
/* create a new obstack */
old_obst = irg->obst;
new_obst = XMALLOC(struct obstack);
struct obstack *old_obst = irg->obst;
struct obstack *new_obst = XMALLOC(struct obstack);
obstack_init(new_obst);
irg->obst = new_obst;
irg->last_node_idx = 0;
......
......@@ -147,8 +147,6 @@ static const arch_register_t *map_i_to_o_reg(const arch_register_t *reg)
static void check_omit_fp(ir_node *node, void *env)
{
bool *can_omit_fp = (bool*) env;
/* omit-fp is not possible if:
* - we have allocations on the stack
* - we have calls (with the exception of tail-calls once we support them)
......@@ -156,6 +154,7 @@ static void check_omit_fp(ir_node *node, void *env)
if ((is_Alloc(node) && get_Alloc_where(node) == stack_alloc)
|| (is_Free(node) && get_Free_where(node) == stack_alloc)
|| is_Call(node)) {
bool *can_omit_fp = (bool*) env;
*can_omit_fp = false;
}
}
......@@ -178,24 +177,7 @@ static unsigned determine_n_float_regs(ir_mode *mode)
calling_convention_t *sparc_decide_calling_convention(ir_type *function_type,
ir_graph *irg)
{
unsigned stack_offset = 0;
unsigned n_param_regs_used = 0;
int n_param_regs = ARRAY_SIZE(param_regs);
unsigned n_float_result_regs = ARRAY_SIZE(float_result_regs);
bool omit_fp = false;
mtp_additional_properties mtp
= get_method_additional_properties(function_type);
reg_or_stackslot_t *params;
reg_or_stackslot_t *results;
int n_params;
int n_results;
int i;
int regnum;
unsigned float_regnum;
unsigned n_reg_results = 0;
calling_convention_t *cconv;
unsigned *caller_saves;
bool omit_fp = false;
if (irg != NULL) {
omit_fp = be_options.omit_fp;
/* our current vaarg handling needs the standard space to store the
......@@ -207,7 +189,9 @@ calling_convention_t *sparc_decide_calling_convention(ir_type *function_type,
}
}
caller_saves = rbitset_malloc(N_SPARC_REGISTERS);
mtp_additional_properties mtp
= get_method_additional_properties(function_type);
unsigned *caller_saves = rbitset_malloc(N_SPARC_REGISTERS);
if (mtp & mtp_property_returns_twice) {
rbitset_copy(caller_saves, default_returns_twice_saves,
N_SPARC_REGISTERS);
......@@ -216,11 +200,13 @@ calling_convention_t *sparc_decide_calling_convention(ir_type *function_type,
}
/* determine how parameters are passed */
n_params = get_method_n_params(function_type);
regnum = 0;
params = XMALLOCNZ(reg_or_stackslot_t, n_params);
int n_params = get_method_n_params(function_type);
int regnum = 0;
reg_or_stackslot_t *params = XMALLOCNZ(reg_or_stackslot_t, n_params);
for (i = 0; i < n_params; ++i) {
int n_param_regs = ARRAY_SIZE(param_regs);
unsigned stack_offset = 0;
for (int i = 0; i < n_params; ++i) {
ir_type *param_type = get_method_param_type(function_type,i);
ir_mode *mode;
int bits;
......@@ -281,14 +267,16 @@ calling_convention_t *sparc_decide_calling_convention(ir_type *function_type,
}
}
}
n_param_regs_used = regnum;
unsigned n_param_regs_used = regnum;
/* determine how results are passed */
n_results = get_method_n_ress(function_type);
regnum = 0;
float_regnum = 0;
results = XMALLOCNZ(reg_or_stackslot_t, n_results);
for (i = 0; i < n_results; ++i) {
int n_results = get_method_n_ress(function_type);
unsigned float_regnum = 0;
unsigned n_reg_results = 0;
unsigned n_float_result_regs = ARRAY_SIZE(float_result_regs);
reg_or_stackslot_t *results = XMALLOCNZ(reg_or_stackslot_t, n_results);
regnum = 0;
for (int i = 0; i < n_results; ++i) {
ir_type *result_type = get_method_res_type(function_type, i);
ir_mode *result_mode = get_type_mode(result_type);
reg_or_stackslot_t *result = &results[i];
......@@ -339,7 +327,7 @@ calling_convention_t *sparc_decide_calling_convention(ir_type *function_type,
}
}
cconv = XMALLOCZ(calling_convention_t);
calling_convention_t *cconv = XMALLOCZ(calling_convention_t);
cconv->parameters = params;
cconv->param_stack_size = stack_offset;
cconv->n_param_regs = n_param_regs_used;
......@@ -375,26 +363,25 @@ void sparc_free_calling_convention(calling_convention_t *cconv)
void sparc_cconv_init(void)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(caller_saves); ++i) {
for (size_t i = 0; i < ARRAY_SIZE(caller_saves); ++i) {
rbitset_set(default_caller_saves, caller_saves[i]);
}
rbitset_set_all(default_returns_twice_saves, N_SPARC_REGISTERS);
for (i = 0; i < ARRAY_SIZE(returns_twice_saved); ++i) {
for (size_t i = 0; i < ARRAY_SIZE(returns_twice_saved); ++i) {
rbitset_clear(default_returns_twice_saves, returns_twice_saved[i]);
}
for (i = 0; i < ARRAY_SIZE(ignore_regs); ++i) {
for (size_t i = 0; i < ARRAY_SIZE(ignore_regs); ++i) {
rbitset_clear(default_returns_twice_saves, ignore_regs[i]);
}
for (i = 0; i < ARRAY_SIZE(float_result_reqs_double); i += 2) {
for (size_t i = 0; i < ARRAY_SIZE(float_result_reqs_double); i += 2) {
arch_register_req_t *req = &float_result_reqs_double[i];
*req = *float_result_regs[i]->single_req;
req->type |= arch_register_req_type_aligned;
req->width = 2;
}
for (i = 0; i < ARRAY_SIZE(float_result_reqs_quad); i += 4) {
for (size_t i = 0; i < ARRAY_SIZE(float_result_reqs_quad); i += 4) {
arch_register_req_t *req = &float_result_reqs_quad[i];
*req = *float_result_regs[i]->single_req;
req->type |= arch_register_req_type_aligned;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment