Commit e269bd7d authored by Matthias Braun's avatar Matthias Braun
Browse files

bestack: code cleanup, use C99

parent bd973688
......@@ -71,8 +71,6 @@ typedef struct be_irg_t {
be_stack_layout_t stack_layout;
unsigned *allocatable_regs; /**< registers available for the
allocator */
arch_register_req_t const *sp_req; /**< requirements for stackpointer producing
nodes. */
struct obstack obst; /**< birg obstack (mainly used to keep
register constraints which we can't keep
in the irg obst, because it gets replaced
......
......@@ -29,25 +29,19 @@
int be_get_stack_entity_offset(be_stack_layout_t *frame, ir_entity *ent,
int bias)
{
ir_type *t = get_entity_owner(ent);
int ofs = get_entity_offset(ent);
int index;
ir_type *t = get_entity_owner(ent);
int ofs = get_entity_offset(ent);
/* Find the type the entity is contained in. */
for (index = 0; index < N_FRAME_TYPES; ++index) {
for (unsigned index = 0; index < N_FRAME_TYPES; ++index) {
if (frame->order[index] == t)
break;
/* Add the size of all the types below the one of the entity to the entity's offset */
ofs += get_type_size_bytes(frame->order[index]);
}
/* correct the offset by the initial position of the frame pointer */
ofs -= frame->initial_offset;
/* correct the offset with the current bias. */
ofs += bias;
return ofs;
}
......@@ -56,22 +50,18 @@ int be_get_stack_entity_offset(be_stack_layout_t *frame, ir_entity *ent,
*/
static ir_entity *search_ent_with_offset(ir_type *t, int offset)
{
int i, n;
for (i = 0, n = get_compound_n_members(t); i < n; ++i) {
for (int i = 0, n = get_compound_n_members(t); i < n; ++i) {
ir_entity *ent = get_compound_member(t, i);
if (get_entity_offset(ent) == offset)
return ent;
}
return NULL;
}
static void stack_frame_compute_initial_offset(be_stack_layout_t *frame)
{
ir_type *base = frame->between_type;
ir_entity *ent = search_ent_with_offset(base, 0);
ir_type *base = frame->between_type;
ir_entity *ent = search_ent_with_offset(base, 0);
if (ent == NULL) {
frame->initial_offset = get_type_size_bytes(frame->frame_type);
} else {
......@@ -85,33 +75,25 @@ static void stack_frame_compute_initial_offset(be_stack_layout_t *frame)
*/
static void lower_outer_frame_members(ir_node *sel, void *ctx)
{
ir_node *ptr;
ir_entity *ent;
ir_type *owner;
be_stack_layout_t *layout;
ir_graph *irg;
(void) ctx;
(void)ctx;
if (!is_Member(sel))
return;
ent = get_Member_entity(sel);
owner = get_entity_owner(ent);
ptr = get_Member_ptr(sel);
irg = get_irn_irg(sel);
layout = be_get_irg_stack_layout(irg);
ir_entity *ent = get_Member_entity(sel);
ir_type *owner = get_entity_owner(ent);
ir_node *ptr = get_Member_ptr(sel);
ir_graph *irg = get_irn_irg(sel);
be_stack_layout_t *layout = be_get_irg_stack_layout(irg);
if (owner == layout->frame_type || owner == layout->arg_type) {
/* found access to outer frame or arguments */
int offset = be_get_stack_entity_offset(layout, ent, 0);
if (offset != 0) {
ir_node *bl = get_nodes_block(sel);
dbg_info *dbgi = get_irn_dbg_info(sel);
ir_mode *mode = get_irn_mode(sel);
ir_node *bl = get_nodes_block(sel);
dbg_info *dbgi = get_irn_dbg_info(sel);
ir_mode *mode = get_irn_mode(sel);
ir_mode *mode_UInt = get_reference_mode_unsigned_eq(mode);
ir_node *cnst = new_r_Const_long(irg, mode_UInt, offset);
ir_node *cnst = new_r_Const_long(irg, mode_UInt, offset);
ptr = new_rd_Add(dbgi, bl, ptr, cnst, mode);
}
exchange(sel, ptr);
......@@ -143,13 +125,9 @@ static int process_stack_bias(ir_node *bl, int real_bias)
const arch_env_t *arch_env = be_get_irg_arch_env(irg);
sched_foreach(bl, irn) {
int ofs;
/*
Check, if the node relates to an entity on the stack frame.
If so, set the true offset (including the bias) for that
node.
*/
/* Check, if the node relates to an entity on the stack frame.
* If so, set the true offset (including the bias) for that
* node. */
ir_entity *ent = arch_get_frame_entity(irn);
if (ent != NULL) {
int bias = sp_relative ? real_bias : 0;
......@@ -157,12 +135,10 @@ static int process_stack_bias(ir_node *bl, int real_bias)
arch_set_frame_offset(irn, offset);
}
/*
* If the node modifies the stack pointer by a constant offset,
* record that in the bias.
*/
/* If the node modifies the stack pointer by a constant offset,
* record that in the bias. */
if (be_is_IncSP(irn)) {
ofs = be_get_IncSP_offset(irn);
int ofs = be_get_IncSP_offset(irn);
/* fill in real stack frame size */
if (be_get_IncSP_align(irn)) {
/* patch IncSP to produce an aligned stack pointer */
......@@ -186,7 +162,7 @@ static int process_stack_bias(ir_node *bl, int real_bias)
real_bias += ofs;
wanted_bias += ofs;
} else {
ofs = arch_get_sp_bias(irn);
int ofs = arch_get_sp_bias(irn);
if (ofs == SP_BIAS_RESET) {
real_bias = 0;
wanted_bias = 0;
......@@ -208,21 +184,18 @@ static int process_stack_bias(ir_node *bl, int real_bias)
static void stack_bias_walker(ir_node *bl, void *data)
{
bias_walk *bw = (bias_walk*)data;
if (bl != bw->start_block) {
if (bl != bw->start_block)
process_stack_bias(bl, bw->start_block_bias);
}
}
void be_abi_fix_stack_bias(ir_graph *irg)
{
be_stack_layout_t *stack_layout = be_get_irg_stack_layout(irg);
ir_type *frame_tp;
int i;
bias_walk bw;
stack_frame_compute_initial_offset(stack_layout);
/* Determine the stack bias at the end of the start block. */
bias_walk bw;
bw.start_block = get_irg_start_block(irg);
bw.start_block_bias = process_stack_bias(bw.start_block, stack_layout->initial_bias);
......@@ -231,8 +204,8 @@ void be_abi_fix_stack_bias(ir_graph *irg)
/* fix now inner functions: these still have Sel node to outer
frame and parameter entities */
frame_tp = get_irg_frame_type(irg);
for (i = get_class_n_members(frame_tp) - 1; i >= 0; --i) {
ir_type *frame_tp = get_irg_frame_type(irg);
for (unsigned i = get_class_n_members(frame_tp); i-- > 0; ) {
ir_entity *ent = get_class_member(frame_tp, i);
if (!is_method_entity(ent))
continue;
......@@ -265,25 +238,19 @@ static void collect_stack_nodes_walker(ir_node *node, void *data)
void be_abi_fix_stack_nodes(ir_graph *irg)
{
be_lv_t *lv = be_get_irg_liveness(irg);
const arch_env_t *arch_env = be_get_irg_arch_env(irg);
be_irg_t *birg = be_birg_from_irg(irg);
const arch_register_t *sp = arch_env->sp;
be_ssa_construction_env_t senv;
int len;
ir_node **phis;
fix_stack_walker_env_t walker_env;
be_lv_t *lv = be_get_irg_liveness(irg);
const arch_env_t *arch_env = be_get_irg_arch_env(irg);
be_irg_t *birg = be_birg_from_irg(irg);
const arch_register_t *sp = arch_env->sp;
arch_register_req_t const *sp_req = birg->sp_req;
if (sp_req == NULL) {
arch_register_req_type_t type = arch_register_req_type_produces_sp;
if (!rbitset_is_set(birg->allocatable_regs, sp->global_index))
type |= arch_register_req_type_ignore;
arch_register_req_type_t type = arch_register_req_type_produces_sp;
if (!rbitset_is_set(birg->allocatable_regs, sp->global_index))
type |= arch_register_req_type_ignore;
struct obstack *const obst = be_get_be_obst(irg);
birg->sp_req = sp_req = be_create_reg_req(obst, sp, type);
}
struct obstack *const obst = be_get_be_obst(irg);
const arch_register_req_t *sp_req = be_create_reg_req(obst, sp, type);
fix_stack_walker_env_t walker_env;
walker_env.sp_nodes = NEW_ARR_F(ir_node*, 0);
irg_walk_graph(irg, collect_stack_nodes_walker, NULL, &walker_env);
......@@ -292,12 +259,13 @@ void be_abi_fix_stack_nodes(ir_graph *irg)
* continue, as for endless loops incsp might have had no users and is bad
* now.
*/
len = ARR_LEN(walker_env.sp_nodes);
int len = ARR_LEN(walker_env.sp_nodes);
if (len == 0) {
DEL_ARR_F(walker_env.sp_nodes);
return;
}
be_ssa_construction_env_t senv;
be_ssa_construction_init(&senv, irg);
be_ssa_construction_add_copies(&senv, walker_env.sp_nodes,
ARR_LEN(walker_env.sp_nodes));
......@@ -312,7 +280,7 @@ void be_abi_fix_stack_nodes(ir_graph *irg)
be_ssa_construction_update_liveness_phis(&senv, lv);
}
phis = be_ssa_construction_get_new_phis(&senv);
ir_node **phis = be_ssa_construction_get_new_phis(&senv);
/* set register requirements for stack phis */
len = ARR_LEN(phis);
......@@ -331,9 +299,8 @@ void be_abi_fix_stack_nodes(ir_graph *irg)
* them all). Remove unnecessary keeps and IncSP nodes */
ir_node *end = get_irg_end(irg);
foreach_irn_in_r(end, i, in) {
if (!be_is_IncSP(in)) {
if (!be_is_IncSP(in))
continue;
}
remove_End_keepalive(end, in);
if (get_irn_n_edges(in) == 0) {
......
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