Commit 429d687f authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Add ALLOCAN() and ALLOCANZ().

[r22985]
parent 38249b03
......@@ -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__)
......
......@@ -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;
......
......@@ -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();
/*
......
......@@ -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));
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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)
......
......@@ -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)
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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';
......
......@@ -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]));
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
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