X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flower%2Flower_hl.c;h=70f44f4de25652cbdc13e2bd58f2cf412623d69b;hb=3a47171668b40b487a2a3d3c4e5fa3e3e76301c6;hp=27598f277d3cb9ced5d1a4f9b0add5a4dd5a312d;hpb=d92c40358495a9da07dcb03c9ad418bf460825b0;p=libfirm diff --git a/ir/lower/lower_hl.c b/ir/lower/lower_hl.c index 27598f277..70f44f4de 100644 --- a/ir/lower/lower_hl.c +++ b/ir/lower/lower_hl.c @@ -35,11 +35,14 @@ #include "irhooks.h" #include "irgmod.h" #include "irgwalk.h" +#include "irtools.h" +#include "irpass_t.h" /** * Lower a Sel node. Do not touch Sels accessing entities on the frame type. */ -static void lower_sel(ir_node *sel) { +static void lower_sel(ir_node *sel) +{ ir_graph *irg = current_ir_graph; ir_entity *ent; ir_node *newn, *cnst, *index, *ptr, *bl; @@ -210,14 +213,12 @@ static void lower_sel(ir_node *sel) { #else /* normal code */ newn = new_rd_Load(dbg, bl, get_Sel_mem(sel), add, ent_mode, 0); #endif - newn = new_r_Proj(bl, newn, ent_mode, pn_Load_res); + newn = new_r_Proj(newn, ent_mode, pn_Load_res); } else if (get_entity_owner(ent) != get_glob_type()) { int offset; /* replace Sel by add(obj, const(ent.offset)) */ - assert(!(get_entity_allocation(ent) == allocation_static && - (get_entity_n_overwrites(ent) == 0 && get_entity_n_overwrittenby(ent) == 0))); newn = get_Sel_ptr(sel); offset = get_entity_offset(ent); if (offset != 0) { @@ -241,7 +242,8 @@ static void lower_sel(ir_node *sel) { /** * Lower a all possible SymConst nodes. */ -static void lower_symconst(ir_node *symc) { +static void lower_symconst(ir_node *symc) +{ ir_node *newn; ir_type *tp; ir_entity *ent; @@ -275,9 +277,6 @@ static void lower_symconst(ir_node *symc) { hook_lower(symc); exchange(symc, newn); break; - case symconst_addr_name: - /* do not rewrite - pass info to back end */ - break; case symconst_addr_ent: /* leave */ break; @@ -315,7 +314,8 @@ static void lower_symconst(ir_node *symc) { * * @param size the size on bits */ -static int is_integral_size(int size) { +static int is_integral_size(int size) +{ /* must be a 2^n */ if (size & (size-1)) return 0; @@ -329,7 +329,8 @@ static int is_integral_size(int size) { * @param proj the Proj(result) node * @param load the Load node */ -static void lower_bitfields_loads(ir_node *proj, ir_node *load) { +static void lower_bitfields_loads(ir_node *proj, ir_node *load) +{ ir_node *sel = get_Load_ptr(load); ir_node *block, *n_proj, *res, *ptr; ir_entity *ent; @@ -382,7 +383,7 @@ static void lower_bitfields_loads(ir_node *proj, ir_node *load) { /* create new proj, switch off CSE or we may get the old one back */ old_cse = get_opt_cse(); set_opt_cse(0); - res = n_proj = new_r_Proj(block, load, mode, pn_Load_res); + res = n_proj = new_r_Proj(load, mode, pn_Load_res); set_opt_cse(old_cse); if (mode_is_signed(mode)) { /* signed */ @@ -415,7 +416,8 @@ static void lower_bitfields_loads(ir_node *proj, ir_node *load) { * * @todo: It adds a load which may produce an exception! */ -static void lower_bitfields_stores(ir_node *store) { +static void lower_bitfields_stores(ir_node *store) +{ ir_node *sel = get_Store_ptr(store); ir_node *ptr, *value; ir_entity *ent; @@ -471,9 +473,9 @@ static void lower_bitfields_stores(ir_node *store) { if (neg_mask) { /* there are some bits, normal case */ - irn = new_r_Load( block, mem, ptr, mode, 0); - mem = new_r_Proj( block, irn, mode_M, pn_Load_M); - irn = new_r_Proj( block, irn, mode, pn_Load_res); + irn = new_r_Load(block, mem, ptr, mode, 0); + mem = new_r_Proj(irn, mode_M, pn_Load_M); + irn = new_r_Proj(irn, mode, pn_Load_res); irn = new_r_And(block, irn, new_Const_long(mode, neg_mask), mode); @@ -494,7 +496,8 @@ static void lower_bitfields_stores(ir_node *store) { /** * Lowers unaligned Loads. */ -static void lower_unaligned_Load(ir_node *load) { +static void lower_unaligned_Load(ir_node *load) +{ (void) load; /* NYI */ } @@ -502,7 +505,8 @@ static void lower_unaligned_Load(ir_node *load) { /** * Lowers unaligned Stores */ -static void lower_unaligned_Store(ir_node *store) { +static void lower_unaligned_Store(ir_node *store) +{ (void) store; /* NYI */ } @@ -510,7 +514,8 @@ static void lower_unaligned_Store(ir_node *store) { /** * lowers IR-nodes, called from walker */ -static void lower_irnode(ir_node *irn, void *env) { +static void lower_irnode(ir_node *irn, void *env) +{ (void) env; switch (get_irn_opcode(irn)) { case iro_Sel: @@ -533,12 +538,13 @@ static void lower_irnode(ir_node *irn, void *env) { default: break; } -} /* lower_irnode */ +} /** * Walker: lowers IR-nodes for bitfield access */ -static void lower_bf_access(ir_node *irn, void *env) { +static void lower_bf_access(ir_node *irn, void *env) +{ (void) env; switch (get_irn_opcode(irn)) { case iro_Proj: @@ -557,15 +563,15 @@ static void lower_bf_access(ir_node *irn, void *env) { default: break; } -} /* lower_bf_access */ +} /* * Replaces SymConsts by a real constant if possible. * Replace Sel nodes by address computation. Also resolves array access. * Handle Bitfields by added And/Or calculations. */ -void lower_highlevel_graph(ir_graph *irg, int lower_bitfields) { - +void lower_highlevel_graph(ir_graph *irg, int lower_bitfields) +{ if (lower_bitfields) { /* First step: lower bitfield access: must be run as long as Sels still * exists. */ @@ -574,17 +580,46 @@ void lower_highlevel_graph(ir_graph *irg, int lower_bitfields) { /* Finally: lower SymConst-Size and Sel nodes, Casts, unaligned Load/Stores. */ irg_walk_graph(irg, NULL, lower_irnode, NULL); -} /* lower_highlevel_graph */ + + set_irg_outs_inconsistent(irg); +} + +struct pass_t { + ir_graph_pass_t pass; + int lower_bitfields; +}; + +/** + * Wrapper for running lower_highlevel_graph() as an ir_graph pass. + */ +static int lower_highlevel_graph_wrapper(ir_graph *irg, void *context) +{ + struct pass_t *pass = context; + + lower_highlevel_graph(irg, pass->lower_bitfields); + return 0; +} /* lower_highlevel_graph_wrapper */ + +ir_graph_pass_t *lower_highlevel_graph_pass(const char *name, int lower_bitfields) +{ + struct pass_t *pass = XMALLOCZ(struct pass_t); + + pass->lower_bitfields = lower_bitfields; + return def_graph_pass_constructor( + &pass->pass, name ? name : "lower_hl", lower_highlevel_graph_wrapper); +} /* lower_highlevel_graph_pass */ /* * does the same as lower_highlevel() for all nodes on the const code irg */ -void lower_const_code(void) { +void lower_const_code(void) +{ walk_const_code(NULL, lower_irnode, NULL); } /* lower_const_code */ -ir_prog_pass_t *lower_const_code_pass(const char *name) { - return def_prog_pass(name ? name : "lower_const_code", 0, 0, lower_const_code); +ir_prog_pass_t *lower_const_code_pass(const char *name) +{ + return def_prog_pass(name ? name : "lower_const_code", lower_const_code); } /* @@ -592,7 +627,8 @@ ir_prog_pass_t *lower_const_code_pass(const char *name) { * Replace Sel nodes by address computation. Also resolves array access. * Handle Bitfields by added And/Or calculations. */ -void lower_highlevel(int lower_bitfields) { +void lower_highlevel(int lower_bitfields) +{ int i, n; n = get_irp_n_irgs();