Add ALLOCAN() and ALLOCANZ().
authorChristoph Mallon <christoph.mallon@gmx.de>
Sat, 18 Oct 2008 10:56:50 +0000 (10:56 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sat, 18 Oct 2008 10:56:50 +0000 (10:56 +0000)
[r22985]

36 files changed:
include/libfirm/adt/xmalloc.h
ir/be/beabi.c
ir/be/bechordal.c
ir/be/bechordal_main.c
ir/be/becopyheur.c
ir/be/becopyheur2.c
ir/be/becopyheur4.c
ir/be/becopyilp.c
ir/be/becopyilp2.c
ir/be/becopyopt.c
ir/be/belower.c
ir/be/bemain.c
ir/be/benode.c
ir/be/bepeephole.c
ir/be/beschedrss.c
ir/be/bespill.c
ir/be/bespillbelady.c
ir/be/bespillbelady2.c
ir/be/bespilldaemel.c
ir/be/bespillslots.c
ir/be/bessaconstr.c
ir/be/bestate.c
ir/be/betranshlp.c
ir/be/beverify.c
ir/be/ia32/bearch_ia32.c
ir/be/ia32/ia32_common_transform.c
ir/be/ia32/ia32_transform.c
ir/be/mips/bearch_mips.c
ir/external/read.c
ir/ir/irprofile.c
ir/lower/lower_hl.c
ir/lower/lower_mode_b.c
ir/opt/data_flow_scalar_replace.c
ir/opt/return.c
ir/opt/tropt.c
ir/tr/type.c

index 737d0b4..6e0283c 100644 (file)
@@ -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__)
index 6123524..5a39c29 100644 (file)
@@ -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;
index 4b96b97..ade9717 100644 (file)
@@ -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();
 
        /*
index 1a395c9..05611be 100644 (file)
@@ -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));
index 79afaba..58158c1 100644 (file)
@@ -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; i<ou->node_count; ++i) {
                int is_safe = 1;
index 87136ee..411646e 100644 (file)
@@ -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;
index 4a8cd15..bc33dd4 100644 (file)
@@ -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);
index ae9dd02..b4242fe 100644 (file)
@@ -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)
index 768e47d..b0cd699 100644 (file)
@@ -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; i<len; ++i)
index 780f366..917b2ca 100644 (file)
@@ -307,11 +307,11 @@ static int ou_max_ind_set_costs(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; i<ou->node_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;
index bd9413b..24bc663 100644 (file)
@@ -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) {
index b7943de..a44121f 100644 (file)
@@ -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';
 
index 5daec0e..2ec36ce 100644 (file)
@@ -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]));
index 574d6a6..c8869dd 100644 (file)
@@ -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);
index 44e9be5..3659127 100644 (file)
@@ -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);
index 04c8860..6df8bc7 100644 (file)
@@ -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);
 
index 68256bb..4e4000d 100644 (file)
@@ -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);
index 5377e76..a0aa866 100644 (file)
@@ -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;
index be54899..047fab5 100644 (file)
@@ -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;
index 10599ce..bba1a81 100644 (file)
@@ -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);
 
index eaf3a51..bf5ae96 100644 (file)
@@ -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);
 
index fc79f71..7adc54b 100644 (file)
@@ -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);
index ab4a4c6..d8835ca 100644 (file)
@@ -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);
index de4cf4a..7e18c11 100644 (file)
@@ -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);
index eddb79f..e783b2f 100644 (file)
@@ -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) {
index d91cbf3..2af6020 100644 (file)
@@ -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;
index 1e3be49..6fe28ab 100644 (file)
@@ -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;
 
index 569551b..86e2830 100644 (file)
@@ -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);
index e5ab51e..5cbe392 100644 (file)
@@ -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;
index 472598f..71b7dde 100644 (file)
@@ -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);
        }
index 10fb290..98ebc32 100644 (file)
@@ -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");
index baa151f..c10118a 100644 (file)
@@ -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;
index 7ff3ecf..5051970 100644 (file)
@@ -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)
index 426ea72..ad417aa 100644 (file)
@@ -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;
index 536abae..58fecf8 100644 (file)
@@ -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);
index 562cb66..869bc79 100644 (file)
@@ -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);