From 429d687f06baeeb63d04750f846d39e55fb62343 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Sat, 18 Oct 2008 10:56:50 +0000 Subject: [PATCH] Add ALLOCAN() and ALLOCANZ(). [r22985] --- include/libfirm/adt/xmalloc.h | 10 ++++++++++ ir/be/beabi.c | 3 +-- ir/be/bechordal.c | 4 ++-- ir/be/bechordal_main.c | 2 +- ir/be/becopyheur.c | 10 +++++----- ir/be/becopyheur2.c | 6 +++--- ir/be/becopyheur4.c | 15 +++++++-------- ir/be/becopyilp.c | 16 +++++++++------- ir/be/becopyilp2.c | 25 +++++++++++++------------ ir/be/becopyopt.c | 18 +++++++++--------- ir/be/belower.c | 19 ++++++++----------- ir/be/bemain.c | 4 ++-- ir/be/benode.c | 8 ++++---- ir/be/bepeephole.c | 4 ++-- ir/be/beschedrss.c | 10 +++++----- ir/be/bespill.c | 4 ++-- ir/be/bespillbelady.c | 6 +++--- ir/be/bespillbelady2.c | 2 +- ir/be/bespilldaemel.c | 2 +- ir/be/bespillslots.c | 29 ++++++++++++----------------- ir/be/bessaconstr.c | 4 ++-- ir/be/bestate.c | 11 ++++++----- ir/be/betranshlp.c | 2 +- ir/be/beverify.c | 14 +++++++------- ir/be/ia32/bearch_ia32.c | 21 ++++++++++----------- ir/be/ia32/ia32_common_transform.c | 3 +-- ir/be/ia32/ia32_transform.c | 2 +- ir/be/mips/bearch_mips.c | 2 +- ir/external/read.c | 2 +- ir/ir/irprofile.c | 4 ++-- ir/lower/lower_hl.c | 8 ++++---- ir/lower/lower_mode_b.c | 4 ++-- ir/opt/data_flow_scalar_replace.c | 5 ++--- ir/opt/return.c | 13 ++++++------- ir/opt/tropt.c | 13 ++++++++----- ir/tr/type.c | 18 ++++++------------ 36 files changed, 160 insertions(+), 163 deletions(-) diff --git a/include/libfirm/adt/xmalloc.h b/include/libfirm/adt/xmalloc.h index 737d0b4e4..6e0283c02 100644 --- a/include/libfirm/adt/xmalloc.h +++ b/include/libfirm/adt/xmalloc.h @@ -79,6 +79,16 @@ char *xstrdup(const char *str); */ #define XMALLOCFZ(type, member, n) ((type*)memset(xmalloc(offsetof(type, member) + sizeof(((type*)0)->member) * (n)), 0, offsetof(type, member) + sizeof(((type*)0)->member) * (n))) +/** + * Allocate n objects of a certain type on the stack + */ +#define ALLOCAN(type, n) ((type*)alloca(sizeof(type) * (n))) + +/** + * Allocate n objects of a certain type on the stack and zero them + */ +#define ALLOCANZ(type, n) ((type*)memset((type*)alloca(sizeof(type) * (n)), 0, sizeof(type) * (n))) + /* Includes for alloca() */ #if defined(__FreeBSD__) diff --git a/ir/be/beabi.c b/ir/be/beabi.c index 612352417..5a39c296c 100644 --- a/ir/be/beabi.c +++ b/ir/be/beabi.c @@ -599,8 +599,7 @@ static ir_node *adjust_call(be_abi_irg_t *env, ir_node *irn, ir_node *curr_sp) /* search the greatest result proj number */ - res_projs = alloca(n_res * sizeof(res_projs[0])); - memset(res_projs, 0, n_res * sizeof(res_projs[0])); + res_projs = ALLOCANZ(ir_node*, n_res); foreach_out_edge(irn, edge) { const ir_edge_t *res_edge; diff --git a/ir/be/bechordal.c b/ir/be/bechordal.c index 4b96b9782..ade971731 100644 --- a/ir/be/bechordal.c +++ b/ir/be/bechordal.c @@ -534,10 +534,10 @@ static ir_node *handle_constraints(be_chordal_alloc_env_t *alloc_env, n_regs = env->cls->n_regs; bs = bitset_alloca(n_regs); - alloc_nodes = alloca(n_regs * sizeof(alloc_nodes[0])); + alloc_nodes = ALLOCAN(ir_node*, n_regs); //bp = hungarian_new(n_regs, n_regs, 2, HUNGARIAN_MATCH_PERFECT); bp = bipartite_new(n_regs, n_regs); - assignment = alloca(n_regs * sizeof(assignment[0])); + assignment = ALLOCAN(int, n_regs); partners = pmap_create(); /* diff --git a/ir/be/bechordal_main.c b/ir/be/bechordal_main.c index 1a395c90e..05611be22 100644 --- a/ir/be/bechordal_main.c +++ b/ir/be/bechordal_main.c @@ -429,7 +429,7 @@ static void be_ra_chordal_main(be_irg_t *birg) /* the backend has its own spiller */ m = arch_env_get_n_reg_class(arch_env); - pse = alloca(m * sizeof(pse[0])); + pse = ALLOCAN(post_spill_env_t, m); for (j = 0; j < m; ++j) { memcpy(&pse[j].cenv, &chordal_env, sizeof(chordal_env)); diff --git a/ir/be/becopyheur.c b/ir/be/becopyheur.c index 79afaba9a..58158c17a 100644 --- a/ir/be/becopyheur.c +++ b/ir/be/becopyheur.c @@ -390,11 +390,11 @@ static inline void qnode_max_ind_set(qnode_t *qn, const unit_t *ou) { * safe: node has no interference, hence it is in every max stable set. * unsafe: node has an interference */ - safe = alloca((ou->node_count-1) * sizeof(*safe)); - safe_costs = 0; - safe_count = 0; - unsafe = alloca((ou->node_count-1) * sizeof(*unsafe)); - unsafe_costs = alloca((ou->node_count-1) * sizeof(*unsafe_costs)); + safe = ALLOCAN(ir_node*, ou->node_count - 1); + safe_costs = 0; + safe_count = 0; + unsafe = ALLOCAN(ir_node*, ou->node_count - 1); + unsafe_costs = ALLOCAN(int, ou->node_count - 1); unsafe_count = 0; for(i=1; inode_count; ++i) { int is_safe = 1; diff --git a/ir/be/becopyheur2.c b/ir/be/becopyheur2.c index 87136eefc..411646e90 100644 --- a/ir/be/becopyheur2.c +++ b/ir/be/becopyheur2.c @@ -530,7 +530,7 @@ static int change_color_not(co2_t *env, const ir_node *irn, col_t not_col, struc /* The node has the color it should not have _and_ has not been visited yet. */ if(!color_is_fix(env, irn)) { int n_regs = env->co->cls->n_regs; - col_cost_pair_t *csts = alloca(n_regs * sizeof(csts[0])); + col_cost_pair_t *csts = ALLOCAN(col_cost_pair_t, n_regs); /* Get the costs for giving the node a specific color. */ determine_color_costs(env, ci, csts); @@ -571,7 +571,7 @@ static int change_color_single(co2_t *env, const ir_node *irn, col_t tgt_col, st if(!color_is_fix(env, irn) && is_color_admissible(env, ci, tgt_col)) { int n_regs = env->co->cls->n_regs; - col_cost_pair_t *seq = alloca(n_regs * sizeof(seq[0])); + col_cost_pair_t *seq = ALLOCAN(col_cost_pair_t, n_regs); /* Get the costs for giving the node a specific color. */ single_color_cost(env, ci, tgt_col, seq); @@ -696,7 +696,7 @@ static void unfix_subtree(co2_cloud_irn_t *ci) static int coalesce_top_down(co2_cloud_irn_t *ci, int child_nr, int depth) { co2_t *env = ci->cloud->env; - col_cost_pair_t *seq = alloca(env->n_regs * sizeof(seq[0])); + col_cost_pair_t *seq = ALLOCAN(col_cost_pair_t, env->n_regs); int is_root = ci->mst_parent == ci; col_t parent_col = is_root ? (col_t) -1 : get_col(env, ci->mst_parent->inh.irn); int min_badness = INT_MAX; diff --git a/ir/be/becopyheur4.c b/ir/be/becopyheur4.c index 4a8cd15b7..bc33dd4e8 100644 --- a/ir/be/becopyheur4.c +++ b/ir/be/becopyheur4.c @@ -932,11 +932,12 @@ static inline int is_loose(co_mst_irn_t *node) /** * Determines the costs for each color if it would be assigned to node @p node. */ -static void determine_color_costs(co_mst_env_t *env, co_mst_irn_t *node, col_cost_t *costs) { - int *neigh_cols = alloca(env->n_regs * sizeof(*neigh_cols)); - int n_loose = 0; +static void determine_color_costs(co_mst_env_t *env, co_mst_irn_t *node, col_cost_t *costs) +{ + int *neigh_cols = ALLOCAN(int, env->n_regs); + int n_loose = 0; real_t coeff; - int i; + int i; for (i = 0; i < env->n_regs; ++i) { neigh_cols[i] = 0; @@ -981,7 +982,7 @@ static int change_node_color_excluded(co_mst_env_t *env, co_mst_irn_t *node, int /* The node has the color it should not have _and_ has not been visited yet. */ if (is_loose(node)) { - col_cost_t *costs = alloca(env->n_regs * sizeof(costs[0])); + col_cost_t *costs = ALLOCAN(col_cost_t, env->n_regs); /* Get the costs for giving the node a specific color. */ determine_color_costs(env, node, costs); @@ -1149,7 +1150,7 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c) { int n_int_chunks = 0; waitq *tmp_chunks = new_waitq(); waitq *best_starts = NULL; - col_cost_t *order = alloca(env->n_regs * sizeof(order[0])); + col_cost_t *order = ALLOCANZ(col_cost_t, env->n_regs); bitset_t *visited; int idx, len, i, nidx, pos; struct list_head changed; @@ -1163,8 +1164,6 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c) { ++env->chunk_visited; /* compute color preference */ - memset(order, 0, env->n_regs * sizeof(order[0])); - for (pos = 0, len = ARR_LEN(c->interfere); pos < len; ++pos) { const ir_node *n = c->interfere[pos]; co_mst_irn_t *node = get_co_mst_irn(env, n); diff --git a/ir/be/becopyilp.c b/ir/be/becopyilp.c index ae9dd027c..b4242fe2b 100644 --- a/ir/be/becopyilp.c +++ b/ir/be/becopyilp.c @@ -106,13 +106,15 @@ size_red_t *new_size_red(copy_opt_t *co) { /** * Checks if a node is simplicial in the graph heeding the already removed nodes. */ -static inline int sr_is_simplicial(size_red_t *sr, const ir_node *ifn) { - int i, o, size = 0; - ir_node **all, *curr; - be_ifg_t *ifg = sr->co->cenv->ifg; - void *iter = be_ifg_neighbours_iter_alloca(ifg); - - all = alloca(be_ifg_degree(ifg, ifn) * sizeof(*all)); +static inline int sr_is_simplicial(size_red_t *sr, const ir_node *ifn) +{ + be_ifg_t *ifg = sr->co->cenv->ifg; + void *iter = be_ifg_neighbours_iter_alloca(ifg); + ir_node **all = ALLOCAN(ir_node*, be_ifg_degree(ifg, ifn)); + ir_node *curr; + int size = 0; + int i; + int o; /* get all non-removed neighbors */ be_ifg_foreach_neighbour(ifg, iter, ifn, curr) diff --git a/ir/be/becopyilp2.c b/ir/be/becopyilp2.c index 768e47d16..b0cd699d4 100644 --- a/ir/be/becopyilp2.c +++ b/ir/be/becopyilp2.c @@ -125,16 +125,17 @@ static void build_coloring_cstr(ilp_env_t *ienv) { } } -static void build_interference_cstr(ilp_env_t *ienv) { - lpp_t *lpp = ienv->lp; - local_env_t *lenv = ienv->env; - be_ifg_t *ifg = ienv->co->cenv->ifg; - int n_colors = lenv->n_colors; - int i, col; - - void *iter = be_ifg_cliques_iter_alloca(ifg); - ir_node **clique = alloca(sizeof(*clique) * n_colors); - int size; +static void build_interference_cstr(ilp_env_t *ienv) +{ + lpp_t *lpp = ienv->lp; + local_env_t *lenv = ienv->env; + be_ifg_t *ifg = ienv->co->cenv->ifg; + int n_colors = lenv->n_colors; + void *iter = be_ifg_cliques_iter_alloca(ifg); + ir_node **clique = ALLOCAN(ir_node*, n_colors); + int size; + int col; + int i; char buf[16]; @@ -414,8 +415,8 @@ static void extend_path(ilp_env_t *ienv, pdeq *path, const ir_node *irn) { /* check for forbidden interferences */ - len = pdeq_len(path); - curr_path = alloca(len * sizeof(*curr_path)); + len = pdeq_len(path); + curr_path = ALLOCAN(ir_node*, len); pdeq_copyl(path, (const void **)curr_path); for (i=1; inode_count-1) * sizeof(*safe)); - safe_costs = 0; - safe_count = 0; - unsafe = alloca((ou->node_count-1) * sizeof(*unsafe)); - unsafe_costs = alloca((ou->node_count-1) * sizeof(*unsafe_costs)); + safe = ALLOCAN(ir_node*, ou->node_count - 1); + safe_costs = 0; + safe_count = 0; + unsafe = ALLOCAN(ir_node*, ou->node_count - 1); + unsafe_costs = ALLOCAN(int, ou->node_count - 1); unsafe_count = 0; for(i=1; inode_count; ++i) { int is_safe = 1; @@ -572,7 +572,7 @@ static void co_sort_units(copy_opt_t *co) { /* get the number of ous, remove them form the list and fill the array */ list_for_each_entry(unit_t, ou, &co->units, units) count++; - ous = alloca(count * sizeof(*ous)); + ous = ALLOCAN(unit_t, count); costs = co_get_max_copy_costs(co); @@ -861,9 +861,9 @@ static int co_dump_appel_disjoint_constraints(const copy_opt_t *co, ir_node *a, void co_dump_appel_graph(const copy_opt_t *co, FILE *f) { - be_ifg_t *ifg = co->cenv->ifg; - int *color_map = alloca(co->cls->n_regs * sizeof(color_map[0])); - int *node_map = XMALLOCN(int, get_irg_last_idx(co->irg) + 1); + be_ifg_t *ifg = co->cenv->ifg; + int *color_map = ALLOCAN(int, co->cls->n_regs); + int *node_map = XMALLOCN(int, get_irg_last_idx(co->irg) + 1); ir_node *irn; void *it, *nit; diff --git a/ir/be/belower.c b/ir/be/belower.c index bd9413b39..24bc66351 100644 --- a/ir/be/belower.c +++ b/ir/be/belower.c @@ -291,7 +291,7 @@ static void lower_perm_node(ir_node *irn, lower_env_t *env) ir_graph *const irg = get_irn_irg(irn); ir_node *const block = get_nodes_block(irn); int const arity = get_irn_arity(irn); - reg_pair_t *const pairs = alloca(arity * sizeof(pairs[0])); + reg_pair_t *const pairs = ALLOCAN(reg_pair_t, arity); int keep_perm = 0; int do_copy = env->do_copy; /* Get the schedule predecessor node to the perm. @@ -767,7 +767,6 @@ static void melt_copykeeps(constraint_env_t *cenv) { void assure_constraints(be_irg_t *birg) { ir_graph *irg = be_get_birg_irg(birg); constraint_env_t cenv; - ir_node **nodes; ir_nodemap_iterator_t map_iter; ir_nodemap_entry_t map_entry; @@ -786,15 +785,13 @@ void assure_constraints(be_irg_t *birg) { /* for all */ foreach_ir_nodemap(&cenv.op_set, map_entry, map_iter) { - op_copy_assoc_t *entry = map_entry.data; - int n; - ir_node *cp; - ir_nodeset_iterator_t iter; + op_copy_assoc_t *entry = map_entry.data; + int n = ir_nodeset_size(&entry->copies); + ir_node **nodes = ALLOCAN(ir_node*, n); + ir_node *cp; + ir_nodeset_iterator_t iter; be_ssa_construction_env_t senv; - n = ir_nodeset_size(&entry->copies); - nodes = alloca(n * sizeof(nodes[0])); - /* put the node in an array */ DBG((dbg_constr, LEVEL_1, "introduce copies for %+F ", map_entry.node)); @@ -966,8 +963,8 @@ found_front: return 0; } - map = alloca(new_size * sizeof(map[0])); - proj_map = alloca(arity * sizeof(proj_map[0])); + map = ALLOCAN(int, new_size); + proj_map = ALLOCAN(int, arity); memset(proj_map, -1, sizeof(proj_map[0])); n = 0; for (i = 0; i < arity; ++i) { diff --git a/ir/be/bemain.c b/ir/be/bemain.c index b7943dead..a44121ffe 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -565,7 +565,7 @@ static void be_main_loop(FILE *file_handle, const char *cup_name) /* we might need 1 birg more for instrumentation constructor */ num_birgs = backend_irg_list ? ARR_LEN(backend_irg_list) : get_irp_n_irgs(); - birgs = alloca(sizeof(birgs[0]) * (num_birgs + 1)); + birgs = ALLOCAN(be_irg_t, num_birgs + 1); /* First: initialize all birgs */ for(i = 0; i < num_birgs; ++i) { @@ -899,7 +899,7 @@ void be_main(FILE *file_handle, const char *cup_name) if (be_options.statev) { const char *dot = strrchr(cup_name, '.'); const char *pos = dot ? dot : cup_name + strlen(cup_name); - char *buf = alloca(pos - cup_name + 1); + char *buf = ALLOCAN(char, pos - cup_name + 1); strncpy(buf, cup_name, pos - cup_name); buf[pos - cup_name] = '\0'; diff --git a/ir/be/benode.c b/ir/be/benode.c index 5daec0e48..2ec36cead 100644 --- a/ir/be/benode.c +++ b/ir/be/benode.c @@ -440,7 +440,7 @@ ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *b void be_Perm_reduce(ir_node *perm, int new_size, int *map) { int arity = get_irn_arity(perm); - be_reg_data_t *old_data = alloca(arity * sizeof(old_data[0])); + be_reg_data_t *old_data = ALLOCAN(be_reg_data_t, arity); be_node_attr_t *attr = get_irn_attr(perm); ir_node **new_in; @@ -474,7 +474,7 @@ ir_node *be_new_MemPerm(const arch_env_t *arch_env, ir_graph *irg, ir_node *bl, ir_node **real_in; int i; - real_in = alloca((n+1) * sizeof(real_in[0])); + real_in = ALLOCAN(ir_node*, n + 1); real_in[0] = frame; memcpy(&real_in[1], in, n * sizeof(real_in[0])); @@ -790,8 +790,8 @@ ir_entity *be_get_FrameAddr_entity(const ir_node *node) ir_node *be_new_CopyKeep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, int n, ir_node *in_keep[], ir_mode *mode) { - ir_node *irn; - ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0])); + ir_node *irn; + ir_node **in = ALLOCAN(ir_node*, n + 1); in[0] = src; memcpy(&in[1], in_keep, n * sizeof(in[0])); diff --git a/ir/be/bepeephole.c b/ir/be/bepeephole.c index 574d6a607..c8869dd63 100644 --- a/ir/be/bepeephole.c +++ b/ir/be/bepeephole.c @@ -384,11 +384,11 @@ void be_peephole_opt(be_irg_t *birg) lv = be_get_birg_liveness(birg); n_classes = arch_env_get_n_reg_class(arch_env); - register_values = alloca(sizeof(register_values[0]) * n_classes); + register_values = ALLOCAN(ir_node**, n_classes); for(i = 0; i < n_classes; ++i) { const arch_register_class_t *cls = arch_env_get_reg_class(arch_env, i); unsigned n_regs = arch_register_class_n_regs(cls); - register_values[i] = alloca(sizeof(ir_node*) * n_regs); + register_values[i] = ALLOCAN(ir_node*, n_regs); } irg_block_walk_graph(irg, process_block, NULL, NULL); diff --git a/ir/be/beschedrss.c b/ir/be/beschedrss.c index 44e9be587..3659127b2 100644 --- a/ir/be/beschedrss.c +++ b/ir/be/beschedrss.c @@ -1347,7 +1347,7 @@ static void compute_dvg(rss_t *rss, dvg_t *dvg) { static void update_dvg(rss_t *rss, dvg_t *dvg, rss_irn_t *src, rss_irn_t *tgt) { int i, j, idx; rss_edge_t *edge; - rss_edge_t **arr = alloca(pset_count(dvg->edges) * sizeof(arr[0])); + rss_edge_t **arr = ALLOCAN(rss_edge_t*, pset_count(dvg->edges)); /* Add an edge from serialization target to serialization src: @@ -1454,9 +1454,9 @@ static void build_dvg_pkiller_list(rss_t *rss, dvg_t *dvg) { */ static ir_nodeset_t *compute_maximal_antichain(rss_t *rss, dvg_t *dvg, int iteration) { int n = ir_nodeset_size(&dvg->nodes); - int *assignment = alloca(n * sizeof(assignment[0])); - int *assignment_rev = alloca(n * sizeof(assignment_rev[0])); - int *idx_map = alloca(n * sizeof(idx_map[0])); + int *assignment = ALLOCAN(int, n); + int *assignment_rev = ALLOCAN(int, n); + int *idx_map = ALLOCAN(int, n); hungarian_problem_t *bp; ir_nodeset_t *values, *temp; ir_nodeset_iterator_t iter; @@ -1718,7 +1718,7 @@ static serialization_t *compute_best_admissible_serialization(rss_t *rss, ir_nod int n = ir_nodeset_size(sat_vals); int n_idx = ARR_LEN_SAFE(rss->idx_map); int i = 0; - ir_node **val_arr = alloca(n * sizeof(val_arr[0])); + ir_node **val_arr = ALLOCAN(ir_node*, n); bitset_t *bs_sv = bitset_alloca(n_idx); bitset_t *bs_vdesc = bitset_alloca(n_idx); bitset_t *bs_tmp = bitset_alloca(n_idx); diff --git a/ir/be/bespill.c b/ir/be/bespill.c index 04c886064..6df8bc7dc 100644 --- a/ir/be/bespill.c +++ b/ir/be/bespill.c @@ -483,7 +483,7 @@ static void spill_phi(spill_env_t *env, spill_info_t *spillinfo) /* build a new PhiM */ arity = get_irn_arity(phi); - ins = alloca(sizeof(ir_node*) * arity); + ins = ALLOCAN(ir_node*, arity); unknown = new_r_Unknown(irg, mode_M); for(i = 0; i < arity; ++i) { ins[i] = unknown; @@ -689,7 +689,7 @@ static ir_node *do_remat(spill_env_t *env, ir_node *spilled, ir_node *reloader) bl = get_nodes_block(reloader); } - ins = alloca(get_irn_arity(spilled) * sizeof(ins[0])); + ins = ALLOCAN(ir_node*, get_irn_arity(spilled)); for(i = 0, arity = get_irn_arity(spilled); i < arity; ++i) { ir_node *arg = get_irn_n(spilled, i); diff --git a/ir/be/bespillbelady.c b/ir/be/bespillbelady.c index 68256bb85..4e4000de2 100644 --- a/ir/be/bespillbelady.c +++ b/ir/be/bespillbelady.c @@ -316,8 +316,8 @@ static inline unsigned get_distance(ir_node *from, unsigned from_step, */ static void displace(workset_t *new_vals, int is_usage) { - ir_node **to_insert = alloca(n_regs * sizeof(to_insert[0])); - bool *spilled = alloca(n_regs * sizeof(spilled[0])); + ir_node **to_insert = ALLOCAN(ir_node*, n_regs); + bool *spilled = ALLOCAN(bool, n_regs); ir_node *val; int i; int len; @@ -551,7 +551,7 @@ static void decide_start_workset(const ir_node *block) /* check predecessors */ arity = get_irn_arity(block); - pred_worksets = alloca(sizeof(pred_worksets[0]) * arity); + pred_worksets = ALLOCAN(workset_t*, arity); all_preds_known = true; for(i = 0; i < arity; ++i) { ir_node *pred_block = get_Block_cfgpred_block(block, i); diff --git a/ir/be/bespillbelady2.c b/ir/be/bespillbelady2.c index 5377e7604..a0aa86647 100644 --- a/ir/be/bespillbelady2.c +++ b/ir/be/bespillbelady2.c @@ -563,7 +563,7 @@ static inline int is_transport_in(const ir_node *bl, const ir_node *irn) static void displace(block_info_t *bi, workset_t *new_vals, int is_usage) { belady_env_t *env = bi->bel; workset_t *ws = env->ws; - ir_node **to_insert = alloca(env->n_regs * sizeof(to_insert[0])); + ir_node **to_insert = ALLOCAN(ir_node*, env->n_regs); int i, len, max_allowed, demand, iter; ir_node *val; diff --git a/ir/be/bespilldaemel.c b/ir/be/bespilldaemel.c index be54899ad..047fab5ce 100644 --- a/ir/be/bespilldaemel.c +++ b/ir/be/bespilldaemel.c @@ -185,7 +185,7 @@ static void do_spilling(ir_nodeset_t *live_nodes, ir_node *node) return; DBG((dbg, LEVEL_2, "\tspills needed after %+F: %d\n", node, spills_needed)); - candidates = alloca(n_live_nodes * sizeof(candidates[0])); + candidates = ALLOCAN(spill_candidate_t, n_live_nodes); /* construct array with spill candidates and calculate their costs */ i = 0; diff --git a/ir/be/bespillslots.c b/ir/be/bespillslots.c index 10599ce97..bba1a8189 100644 --- a/ir/be/bespillslots.c +++ b/ir/be/bespillslots.c @@ -355,9 +355,9 @@ static void do_greedy_coalescing(be_fec_env_t *env) DB((dbg, DBG_COALESCING, "Coalescing %d spillslots\n", spillcount)); - interferences = alloca(spillcount * sizeof(interferences[0])); - spillslot_unionfind = alloca(spillcount * sizeof(spillslot_unionfind[0])); - spilllist = alloca(spillcount * sizeof(spilllist[0])); + interferences = ALLOCAN(bitset_t*, spillcount); + spillslot_unionfind = ALLOCAN(int, spillcount); + spilllist = ALLOCAN(spill_t*, spillcount); uf_init(spillslot_unionfind, 0, spillcount); @@ -581,15 +581,10 @@ static void assign_spill_entity(ir_node *node, ir_entity *entity) */ static void assign_spillslots(be_fec_env_t *env) { - int i; - int spillcount; - spill_t *spill; - spill_slot_t* spillslots; - - spillcount = set_count(env->spills); - spillslots = alloca(spillcount * sizeof(spillslots[0])); - - memset(spillslots, 0, spillcount * sizeof(spillslots[0])); + int spillcount = set_count(env->spills); + spill_slot_t *spillslots = ALLOCANZ(spill_slot_t, spillcount); + spill_t *spill; + int i; /* construct spillslots */ for(spill = set_first(env->spills); spill != NULL; @@ -705,11 +700,11 @@ static void create_memperms(be_fec_env_t *env) memperm_t *memperm; for(memperm = set_first(env->memperms); memperm != NULL; memperm = set_next(env->memperms)) { - int i; - memperm_entry_t *entry; - ir_node *blockend; - ir_node** nodes = alloca(memperm->entrycount * sizeof(nodes[0])); - ir_node* mempermnode; + ir_node **nodes = ALLOCAN(ir_node*, memperm->entrycount); + memperm_entry_t *entry; + ir_node *blockend; + ir_node *mempermnode; + int i; assert(memperm->entrycount > 0); diff --git a/ir/be/bessaconstr.c b/ir/be/bessaconstr.c index eaf3a51ef..bf5ae96dd 100644 --- a/ir/be/bessaconstr.c +++ b/ir/be/bessaconstr.c @@ -116,8 +116,8 @@ ir_node *create_phi(be_ssa_construction_env_t *env, ir_node *block, { int i, n_preds = get_Block_n_cfgpreds(block); ir_graph *irg = get_irn_irg(block); - ir_node *phi; - ir_node **ins = alloca(n_preds * sizeof(ins[0])); + ir_node **ins = ALLOCAN(ir_node*, n_preds); + ir_node *phi; assert(n_preds > 1); diff --git a/ir/be/bestate.c b/ir/be/bestate.c index fc79f711c..7adc54b69 100644 --- a/ir/be/bestate.c +++ b/ir/be/bestate.c @@ -166,12 +166,13 @@ void create_reload(minibelady_env_t *env, ir_node *state, ir_node *before, static void spill_phi(minibelady_env_t *env, ir_node *phi) { - ir_graph *irg = get_irn_irg(phi); - ir_node *block = get_nodes_block(phi); - int i, arity = get_irn_arity(phi); - ir_node **in = alloca(arity * sizeof(in[0])); - ir_node *spill_to_kill = NULL; + ir_graph *irg = get_irn_irg(phi); + ir_node *block = get_nodes_block(phi); + int arity = get_irn_arity(phi); + ir_node **in = ALLOCAN(ir_node*, arity); + ir_node *spill_to_kill = NULL; spill_info_t *spill_info; + int i; /* does a spill exist for the phis value? */ spill_info = get_spill_info(env, phi); diff --git a/ir/be/betranshlp.c b/ir/be/betranshlp.c index ab4a4c67b..d8835ca07 100644 --- a/ir/be/betranshlp.c +++ b/ir/be/betranshlp.c @@ -109,7 +109,7 @@ ir_node *be_duplicate_node(ir_node *node) { add_irn_n(new_node, in); } } else { - ir_node **ins = alloca(arity * sizeof(ins[0])); + ir_node **ins = ALLOCAN(ir_node*, arity); for (i = 0; i < arity; ++i) { ir_node *in = get_irn_n(node, i); ins[i] = be_transform_node(in); diff --git a/ir/be/beverify.c b/ir/be/beverify.c index de4cf4a48..7e18c11c1 100644 --- a/ir/be/beverify.c +++ b/ir/be/beverify.c @@ -544,11 +544,12 @@ static void collect_spills_walker(ir_node *node, void *data) { } } -static void check_spillslot_interference(be_verify_spillslots_env_t *env) { - int spillcount = set_count(env->spills); - spill_t **spills = alloca(spillcount * sizeof(spills[0])); - spill_t *spill; - int i; +static void check_spillslot_interference(be_verify_spillslots_env_t *env) +{ + int spillcount = set_count(env->spills); + spill_t **spills = ALLOCAN(spill_t*, spillcount); + spill_t *spill; + int i; for(spill = set_first(env->spills), i = 0; spill != NULL; spill = set_next(env->spills), ++i) { spills[i] = spill; @@ -820,8 +821,7 @@ static void verify_block_register_allocation(ir_node *block, void *data) { assert(lv->nodes && "live sets must be computed"); n_regs = arch_register_class_n_regs(regclass); - registers = alloca(n_regs * sizeof(registers[0])); - memset(registers, 0, n_regs * sizeof(registers[0])); + registers = ALLOCANZ(ir_node*, n_regs); be_lv_foreach(lv, block, be_lv_state_end, idx) { ir_node *node = be_lv_get_irn(lv, block, idx); diff --git a/ir/be/ia32/bearch_ia32.c b/ir/be/ia32/bearch_ia32.c index eddb79f27..e783b2f2a 100644 --- a/ir/be/ia32/bearch_ia32.c +++ b/ir/be/ia32/bearch_ia32.c @@ -1307,19 +1307,18 @@ static ir_node* create_spproj(ir_node *node, ir_node *pred, int pos) * push/pop into/from memory cascades. This is possible without using * any registers. */ -static void transform_MemPerm(ia32_code_gen_t *cg, ir_node *node) { - ir_graph *irg = get_irn_irg(node); - ir_node *block = get_nodes_block(node); - ir_node *in[1]; - ir_node *keep; - int i, arity; - ir_node *sp = be_abi_get_ignore_irn(cg->birg->abi, &ia32_gp_regs[REG_ESP]); +static void transform_MemPerm(ia32_code_gen_t *cg, ir_node *node) +{ + ir_graph *irg = get_irn_irg(node); + ir_node *block = get_nodes_block(node); + ir_node *sp = be_abi_get_ignore_irn(cg->birg->abi, &ia32_gp_regs[REG_ESP]); + int arity = be_get_MemPerm_entity_arity(node); + ir_node **pops = ALLOCAN(ir_node*, arity); + ir_node *in[1]; + ir_node *keep; + int i; const ir_edge_t *edge; const ir_edge_t *next; - ir_node **pops; - - arity = be_get_MemPerm_entity_arity(node); - pops = alloca(arity * sizeof(pops[0])); /* create Pushs */ for(i = 0; i < arity; ++i) { diff --git a/ir/be/ia32/ia32_common_transform.c b/ir/be/ia32/ia32_common_transform.c index d91cbf336..2af602016 100644 --- a/ir/be/ia32/ia32_common_transform.c +++ b/ir/be/ia32/ia32_common_transform.c @@ -499,8 +499,7 @@ ir_node *gen_ASM(ir_node *node) } arity = get_irn_arity(node); - in = alloca(arity * sizeof(in[0])); - memset(in, 0, arity * sizeof(in[0])); + in = ALLOCANZ(ir_node*, arity); clobbers = get_ASM_clobbers(node); n_clobbers = 0; diff --git a/ir/be/ia32/ia32_transform.c b/ir/be/ia32/ia32_transform.c index 1e3be4993..6fe28ab4b 100644 --- a/ir/be/ia32/ia32_transform.c +++ b/ir/be/ia32/ia32_transform.c @@ -3504,7 +3504,7 @@ static ir_node *gen_be_Return(ir_node *node) /* create a new barrier */ arity = get_irn_arity(barrier); - in = alloca(arity * sizeof(in[0])); + in = ALLOCAN(ir_node*, arity); for (i = 0; i < arity; ++i) { ir_node *new_in; diff --git a/ir/be/mips/bearch_mips.c b/ir/be/mips/bearch_mips.c index 569551b92..86e2830f1 100644 --- a/ir/be/mips/bearch_mips.c +++ b/ir/be/mips/bearch_mips.c @@ -740,7 +740,7 @@ static void mips_get_call_abi(const void *self, ir_type *method_type, be_abi_call_set_flags(abi, call_flags, &mips_abi_callbacks); /* collect the mode for each type */ - modes = alloca(n * sizeof(modes[0])); + modes = ALLOCAN(ir_mode*, n); for (i = 0; i < n; i++) { tp = get_method_param_type(method_type, i); modes[i] = get_type_mode(tp); diff --git a/ir/external/read.c b/ir/external/read.c index e5ab51e1b..5cbe39201 100644 --- a/ir/external/read.c +++ b/ir/external/read.c @@ -1252,7 +1252,7 @@ static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff) VERBOSE_PRINT((stdout, "number of args expected: %d\n", get_method_n_params(mtype))); } - irns = alloca(num * sizeof(ir_node*)); + irns = ALLOCAN(ir_node*, num); for(i = 0; i < num; i++) { irns[i] = find_valueid_in_proc_effects(eff -> effect.call.args[i], proc) -> firmnode; diff --git a/ir/ir/irprofile.c b/ir/ir/irprofile.c index 472598f20..71b7ddebd 100644 --- a/ir/ir/irprofile.c +++ b/ir/ir/irprofile.c @@ -292,7 +292,7 @@ static void create_location_data(dbg_info *dbg, block_id_walker_data_t *wd) pmap_insert(wd->fname_map, (void *)fname, ent); /* initialize file name string constant */ - tarval_string = alloca(sizeof(*tarval_string) * (len)); + tarval_string = ALLOCAN(tarval*, len); for (i = 0; i < len; ++i) { tarval_string[i] = new_tarval_from_long(fname[i], mode_Bs); } @@ -440,7 +440,7 @@ ir_profile_instrument(const char *filename, unsigned flags) set_array_entity_values(bblock_counts, tarval_array, n_blocks); /* initialize function name string constant */ - tarval_string = alloca(sizeof(*tarval_string) * (filename_len)); + tarval_string = ALLOCAN(tarval*, filename_len); for (i = 0; i < filename_len; ++i) { tarval_string[i] = new_tarval_from_long(filename[i], mode_Bs); } diff --git a/ir/lower/lower_hl.c b/ir/lower/lower_hl.c index 10fb2902a..98ebc325c 100644 --- a/ir/lower/lower_hl.c +++ b/ir/lower/lower_hl.c @@ -99,11 +99,11 @@ static void lower_sel(ir_node *sel) { index = get_Sel_index(sel, 0); if (is_Array_type(owner)) { - ir_node *last_size; ir_type *arr_ty = owner; - int dims = get_array_n_dimensions(arr_ty); - int *map = alloca(sizeof(int) * dims); - int i; + int dims = get_array_n_dimensions(arr_ty); + int *map = ALLOCAN(int, dims); + ir_node *last_size; + int i; assert(dims == get_Sel_n_indexs(sel) && "array dimension must match number of indices of Sel node"); diff --git a/ir/lower/lower_mode_b.c b/ir/lower/lower_mode_b.c index baa151fb5..c10118aea 100644 --- a/ir/lower/lower_mode_b.c +++ b/ir/lower/lower_mode_b.c @@ -166,8 +166,8 @@ static ir_node *lower_node(ir_node *node) ir_node **in; ir_node *unknown, *new_phi; - arity = get_irn_arity(node); - in = alloca(arity * sizeof(in[0])); + arity = get_irn_arity(node); + in = ALLOCAN(ir_node*, arity); unknown = new_Unknown(config.lowered_mode); for(i = 0; i < arity; ++i) { in[i] = unknown; diff --git a/ir/opt/data_flow_scalar_replace.c b/ir/opt/data_flow_scalar_replace.c index 7ff3ecfc1..505197012 100644 --- a/ir/opt/data_flow_scalar_replace.c +++ b/ir/opt/data_flow_scalar_replace.c @@ -757,9 +757,8 @@ static void split_phi_mem_edge(ir_node *irn, env_t *env) { irn_blk = get_nodes_block(irn); val_arr = get_irn_link(irn_blk); - n = get_Block_n_cfgpreds(irn_blk); - - in = alloca(sizeof(*in) * n); + n = get_Block_n_cfgpreds(irn_blk); + in = ALLOCAN(ir_node*, n); for(value_ent = set_first(env->set_ent); value_ent; value_ent = set_next(env->set_ent)) if(val_arr[GET_ENT_VNUM(value_ent->ent)].access_type < 3) diff --git a/ir/opt/return.c b/ir/opt/return.c index 426ea72ad..ad417aa46 100644 --- a/ir/opt/return.c +++ b/ir/opt/return.c @@ -73,8 +73,7 @@ void normalize_one_return(ir_graph *irg) { return; } - returns = alloca((n + 7) >> 3); - memset(returns, 0, (n + 7) >> 3); + returns = ALLOCANZ(unsigned char, (n + 7) >> 3); for (n_rets = i = 0; i < n; ++i) { ir_node *node = get_Block_cfgpred(endbl, i); @@ -93,9 +92,9 @@ void normalize_one_return(ir_graph *irg) { if (n_rets <= 1) return; - in = alloca(sizeof(*in) * IMAX(n_rets, n_ret_vals)); - retvals = alloca(sizeof(*retvals) * n_rets * n_ret_vals); - endbl_in = alloca(sizeof(*endbl_in) * n); + in = ALLOCAN(ir_node*, IMAX(n_rets, n_ret_vals)); + retvals = ALLOCAN(ir_node*, n_rets * n_ret_vals); + endbl_in = ALLOCAN(ir_node*, n); last_idx = 0; for (j = i = 0; i < n; ++i) { @@ -268,7 +267,7 @@ void normalize_n_returns(ir_graph *irg) { */ end = get_irg_end(irg); n_ret_vals = get_irn_arity(list); - in = alloca(sizeof(*in) * n_ret_vals); + in = ALLOCAN(ir_node*, n_ret_vals); while (list) { ir_node *ret = list; ir_node *block = get_nodes_block(ret); @@ -341,7 +340,7 @@ void normalize_n_returns(ir_graph *irg) { * Last step: Create a new endblock, with all nodes on the final * list as predecessors. */ - in = alloca(sizeof(*in) * n_finals); + in = ALLOCAN(ir_node*, n_finals); for (i = 0; final; ++i, final = get_irn_link(final)) in[i] = final; diff --git a/ir/opt/tropt.c b/ir/opt/tropt.c index 536abae6d..58fecf84f 100644 --- a/ir/opt/tropt.c +++ b/ir/opt/tropt.c @@ -329,11 +329,14 @@ static void concretize_selected_entity(ir_node *sel) { } } -static void concretize_Phi_type(ir_node *phi) { - int i, n_preds = get_Phi_n_preds(phi); - ir_node **pred = alloca(n_preds * sizeof(ir_node *)); - ir_node *nn; - ir_type *totype, *fromtype; +static void concretize_Phi_type(ir_node *phi) +{ + int n_preds = get_Phi_n_preds(phi); + ir_node **pred = ALLOCAN(ir_node*, n_preds); + ir_node *nn; + ir_type *totype; + ir_type *fromtype; + int i; if (n_preds == 0) return; pred[0] = get_Phi_pred(phi, 0); diff --git a/ir/tr/type.c b/ir/tr/type.c index 562cb6666..869bc792e 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -478,8 +478,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) { if (get_class_n_supertypes(typ1) != get_class_n_supertypes(typ2)) return 0; if (get_class_peculiarity(typ1) != get_class_peculiarity(typ2)) return 0; /** Compare the members **/ - m = alloca(sizeof(ir_entity *) * get_class_n_members(typ1)); - memset(m, 0, sizeof(ir_entity *) * get_class_n_members(typ1)); + m = ALLOCANZ(ir_entity*, get_class_n_members(typ1)); /* First sort the members of typ2 */ for (i = 0; i < get_class_n_members(typ1); i++) { ir_entity *e1 = get_class_member(typ1, i); @@ -495,8 +494,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) { return 0; } /** Compare the supertypes **/ - t = alloca(sizeof(ir_entity *) * get_class_n_supertypes(typ1)); - memset(t, 0, sizeof(ir_entity *) * get_class_n_supertypes(typ1)); + t = ALLOCANZ(ir_type*, get_class_n_supertypes(typ1)); /* First sort the supertypes of typ2 */ for (i = 0; i < get_class_n_supertypes(typ1); i++) { ir_type *t1 = get_class_supertype(typ1, i); @@ -515,8 +513,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) { case tpo_struct: if (get_struct_n_members(typ1) != get_struct_n_members(typ2)) return 0; - m = alloca(sizeof(ir_entity *) * get_struct_n_members(typ1)); - memset(m, 0, sizeof(ir_entity *) * get_struct_n_members(typ1)); + m = ALLOCANZ(ir_entity*, get_struct_n_members(typ1)); /* First sort the members of lt */ for (i = 0; i < get_struct_n_members(typ1); i++) { ir_entity *e1 = get_struct_member(typ1, i); @@ -563,8 +560,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) { case tpo_union: if (get_union_n_members(typ1) != get_union_n_members(typ2)) return 0; - m = alloca(sizeof(ir_entity *) * get_union_n_members(typ1)); - memset(m, 0, sizeof(ir_entity *) * get_union_n_members(typ1)); + m = ALLOCANZ(ir_entity*, get_union_n_members(typ1)); /* First sort the members of lt */ for (i = 0; i < get_union_n_members(typ1); i++) { ir_entity *e1 = get_union_member(typ1, i); @@ -631,8 +627,7 @@ int smaller_type(ir_type *st, ir_type *lt) { if (n_st_members != get_struct_n_members(lt)) return 0; - m = alloca(sizeof(ir_entity *) * n_st_members); - memset(m, 0, sizeof(ir_entity *) * n_st_members); + m = ALLOCANZ(ir_entity*, n_st_members); /* First sort the members of lt */ for (i = 0; i < n_st_members; ++i) { ir_entity *se = get_struct_member(st, i); @@ -682,8 +677,7 @@ int smaller_type(ir_type *st, ir_type *lt) { case tpo_union: n_st_members = get_union_n_members(st); if (n_st_members != get_union_n_members(lt)) return 0; - m = alloca(sizeof(ir_entity *) * n_st_members); - memset(m, 0, sizeof(ir_entity *) * n_st_members); + m = ALLOCANZ(ir_entity*, n_st_members); /* First sort the members of lt */ for (i = 0; i < n_st_members; ++i) { ir_entity *se = get_union_member(st, i); -- 2.20.1