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

remove NEW_ARR_A and use ALLOCAN

All users of NEW_ARR_A used it to construct a simple array, yet noone
cared about it actually being an array with a length field in front. For
this simple use case you should use ALLOCAN.
parent 440cb5e6
......@@ -10,9 +10,22 @@
*/
#include <stdlib.h>
#include "array_t.h"
#include "array.h"
#include "util.h"
#include "xmalloc.h"
#include "fourcc.h"
#define ARR_D_MAGIC FOURCC('A','R','R','D')
#define ARR_A_MAGIC FOURCC('A','R','R','A')
#define ARR_F_MAGIC FOURCC('A','R','R','F')
#ifdef NDEBUG
# define ARR_SET_DBGINF(descr, co) \
((void)(descr), (void)(co), (void)0)
#else
# define ARR_SET_DBGINF(descr, co) \
((descr)->magic = (co))
#endif
/**
* An empty dynamic array descriptor.
......
/*
* This file is part of libFirm.
* Copyright (C) 2012 University of Karlsruhe.
*/
/**
* @file
* @brief Array --- dynamic & flexible arrays.
*/
#ifndef FIRM_ADT_ARRAY_T_H
#define FIRM_ADT_ARRAY_T_H
#include "array.h"
#include "fourcc.h"
#define ARR_D_MAGIC FOURCC('A','R','R','D')
#define ARR_A_MAGIC FOURCC('A','R','R','A')
#define ARR_F_MAGIC FOURCC('A','R','R','F')
#ifdef NDEBUG
# define ARR_SET_DBGINF(descr, co) \
((void)(descr), (void)(co), (void)0)
#else
# define ARR_SET_DBGINF(descr, co) \
((descr)->magic = (co))
#endif
/**
* Create an automatic array which will be deleted at return from function.
* Beware, the data will be allocated on the function stack!
*
* @param type The element type of the new array.
* @param var A lvalue of type (type *) which will hold the new array.
* @param n number of elements in this array.
*
* This macro creates a dynamic array on the functions stack of a given type at runtime.
* The size of the array cannot be changed later.
*/
#define NEW_ARR_A(type, var, n) \
do { \
size_t nelts = (n); \
(var) = (type *)((ir_arr_descr *)alloca(ARR_ELTS_OFFS + sizeof(type) * nelts))->elts; \
ARR_SET_DBGINF(ARR_DESCR ((var)), ARR_A_MAGIC); \
(void)(ARR_DESCR((var))->nelts = nelts); \
} while (0)
/**
* Creates a new automatic array with the same number of elements as a
* given one.
*
* @param type The element type of the new array.
* @param var A lvalue of type (type *) which will hold the new array.
* @param arr An array from which the elements will be duplicated
*
* This macro creates a dynamic array of a given type at runtime.
* The size of the array cannot be changed later.
*
* @return A pointer to the dynamic array (can be used as a pointer to the
* first element of this array).
*/
#define CLONE_ARR_A(type, var, arr) \
NEW_ARR_A(type, (var), ARR_LEN((arr)))
/**
* Duplicates an array and returns a new automatic one.
*
* @param type The element type of the new array.
* @param var A lvalue of type (type *) which will hold the new array.
* @param arr An array from with the number of elements will be taken
*
* This macro creates a dynamic array of a given type at runtime.
* The size of the array cannot be changed later.
*
* @return A pointer to the dynamic array (can be used as a pointer to the
* first element of this array).
*/
#define DUP_ARR_A(type, var, arr) \
do { CLONE_ARR_A(type, (var), (arr)); \
memcpy((var), (arr), sizeof (type) * ARR_LEN((arr))); } \
while (0)
#endif
......@@ -13,7 +13,7 @@
#include "irouts.h"
#include "irnode_t.h"
#include "irmode_t.h"
#include "array_t.h"
#include "array.h"
#include "irprog.h"
#include "entity_t.h"
......@@ -182,8 +182,7 @@ static void analyze_ent_args(ir_entity *ent)
/* A array to save the information for each argument with
mode reference.*/
ptr_access_kind *rw_info;
NEW_ARR_A(ptr_access_kind, rw_info, nparams);
ptr_access_kind *rw_info = ALLOCAN(ptr_access_kind, nparams);
/* We initialize the element with none state. */
for (size_t i = nparams; i-- > 0; )
......
......@@ -20,7 +20,7 @@
#include "irgwalk.h"
#include "irgopt.h"
#include "irtools.h"
#include "array_t.h"
#include "array.h"
#include "debug.h"
#include "error.h"
#include "irflag.h"
......@@ -202,8 +202,7 @@ static void handle_modeb(ir_node *block, ir_node *selector, pn_Cond pnc, env_t *
}
}
if (i < 0) {
ir_node **in;
NEW_ARR_A(ir_node *, in, n);
ir_node **in = ALLOCAN(ir_node*, n);
/* ok, ALL predecessors are either dominated by block OR other block */
if (c_b == NULL) {
ir_graph *irg = get_irn_irg(block);
......
......@@ -19,7 +19,7 @@
#include "irgraph_t.h"
#include "irnode_t.h"
#include "ircons_t.h"
#include "array_t.h"
#include "array.h"
#include "iredges.h"
static inline ir_dom_info *get_dom_info(ir_node *block)
......
......@@ -21,7 +21,7 @@
#include "lower_calls.h"
#include "error.h"
#include "debug.h"
#include "array_t.h"
#include "array.h"
#include "irtools.h"
#include "bearch.h"
......
......@@ -23,7 +23,7 @@
#include "pset_new.h"
#include "util.h"
#include "obst.h"
#include "array_t.h"
#include "array.h"
#include "irtools.h"
#include "lc_opts.h"
#include "lc_opts_enum.h"
......
......@@ -20,7 +20,7 @@
#include "irgmod.h"
#include "iredges_t.h"
#include "irgwalk.h"
#include "array_t.h"
#include "array.h"
#include "raw_bitset.h"
#include "adt/obstack.h"
#include "util.h"
......@@ -539,7 +539,6 @@ static void melt_copykeeps(constraint_env_t *cenv)
if (ck_arr[idx]) {
int j, n_melt;
ir_node **new_ck_in;
ir_node *sched_pt = NULL;
n_melt = 1;
......@@ -575,7 +574,7 @@ static void melt_copykeeps(constraint_env_t *cenv)
melt_arr = (ir_node **)obstack_finish(&obst);
/* melt all found copykeeps */
NEW_ARR_A(ir_node *, new_ck_in, n_melt);
ir_node **new_ck_in = ALLOCAN(ir_node*,n_melt);
for (j = 0; j < n_melt; ++j) {
new_ck_in[j] = get_irn_n(melt_arr[j], 1);
......
......@@ -24,7 +24,7 @@
#include "bitfiddle.h"
#include "raw_bitset.h"
#include "error.h"
#include "array_t.h"
#include "array.h"
#include "irop_t.h"
#include "irmode_t.h"
......@@ -469,9 +469,8 @@ ir_node *be_new_Call(dbg_info *const dbg, ir_node *const bl, ir_node *const mem,
{
be_call_attr_t *a;
int real_n = n_be_Call_first_arg + n;
ir_node **real_in;
ir_node **real_in = ALLOCAN(ir_node*, real_n);
NEW_ARR_A(ir_node *, real_in, real_n);
real_in[n_be_Call_mem] = mem;
real_in[n_be_Call_sp] = sp;
real_in[n_be_Call_ptr] = ptr;
......
......@@ -8,7 +8,7 @@
* @brief Peephole optimization framework keeps track of which registers contain which values
* @author Matthias Braun
*/
#include "array_t.h"
#include "array.h"
#include "bepeephole.h"
#include "iredges_t.h"
......
......@@ -18,7 +18,7 @@
#include "benode.h"
#include "bemodule.h"
#include "util.h"
#include "array_t.h"
#include "array.h"
// XXX there is no one time init for schedulers
//#define NORMAL_DBG
......@@ -292,7 +292,6 @@ static void normal_sched_block(ir_node* block, void* env)
{
ir_node** roots = (ir_node**)get_irn_link(block);
ir_heights_t* heights = (ir_heights_t*)env;
irn_cost_pair* root_costs;
int i;
ir_node** sched;
......@@ -308,7 +307,7 @@ static void normal_sched_block(ir_node* block, void* env)
return;
}
NEW_ARR_A(irn_cost_pair, root_costs, root_count);
irn_cost_pair *root_costs = ALLOCAN(irn_cost_pair, root_count);
for (i = 0; i < root_count; ++i) {
root_costs[i].irn = roots[i];
root_costs[i].cost = get_irn_height(heights, roots[i]);
......
......@@ -28,7 +28,7 @@
#include "irdom.h"
#include "iropt.h"
#include "error.h"
#include "array_t.h"
#include "array.h"
#include "heights.h"
#include "benode.h"
......@@ -1601,8 +1601,7 @@ static ir_node *transform_AM_mem(ir_node *const block,
} else if (is_Proj(src_val) && is_Sync(src_mem)) {
int const arity = get_Sync_n_preds(src_mem);
ir_node **ins;
NEW_ARR_A(ir_node*, ins, arity + 1);
ir_node **ins = ALLOCAN(ir_node*, arity+1);
/* NOTE: This sometimes produces dead-code because the old sync in
* src_mem might not be used anymore, we should detect this case
......
......@@ -21,7 +21,7 @@
#include "irgwalk.h"
#include "obst.h"
#include "pmap.h"
#include "array_t.h"
#include "array.h"
#include "pdeq.h"
#include "debug.h"
#include "error.h"
......@@ -1462,7 +1462,6 @@ static int sim_Perm(x87_state *state, ir_node *irn)
{
int i, n;
ir_node *pred = get_irn_n(irn, 0);
int *stack_pos;
/* handle only floating point Perms */
if (! mode_is_float(get_irn_mode(pred)))
......@@ -1475,7 +1474,7 @@ static int sim_Perm(x87_state *state, ir_node *irn)
different from each other.
So, all we need to do is to permutate the stack state. */
n = get_irn_arity(irn);
NEW_ARR_A(int, stack_pos, n);
int *stack_pos = ALLOCAN(int, n);
/* collect old stack positions */
for (i = 0; i < n; ++i) {
......
......@@ -29,7 +29,7 @@
#include "lower_mode_b.h"
#include "lower_softfloat.h"
#include "debug.h"
#include "array_t.h"
#include "array.h"
#include "error.h"
#include "util.h"
#include "be_t.h"
......
......@@ -20,7 +20,7 @@
#include "iropt_t.h"
#include "irgmod.h"
#include "irhooks.h"
#include "array_t.h"
#include "array.h"
#include "irbackedge_t.h"
#include "irflag_t.h"
#include "iredges_t.h"
......@@ -47,8 +47,7 @@ ir_node *new_rd_ASM(dbg_info *db, ir_node *block, ir_node *mem,
ir_graph *irg = get_irn_irg(block);
int r_arity = arity+1;
ir_node **r_in;
NEW_ARR_A(ir_node*, r_in, r_arity);
ir_node **r_in = ALLOCAN(ir_node*,r_arity);
r_in[0] = mem;
memcpy(&r_in[1], in, arity*sizeof(ir_node*));
......
......@@ -30,7 +30,7 @@
#include "hashptr.h"
#include "irtools.h"
#include "irhooks.h"
#include "array_t.h"
#include "array.h"
#include "vrp.h"
#include "firm_types.h"
#include "bitfiddle.h"
......@@ -4760,11 +4760,10 @@ static ir_node *transform_node_Phi(ir_node *phi)
/* Beware of Phi0 */
if (n > 0) {
ir_node **in;
ir_node *new_phi;
bool has_pin = false;
NEW_ARR_A(ir_node *, in, n);
ir_node **in = ALLOCAN(ir_node*, n);
for (i = 0; i < n; ++i) {
ir_node *pred = get_irn_n(phi, i);
......@@ -4794,7 +4793,7 @@ static ir_node *transform_node_Phi(ir_node *phi)
/* Beware of Phi0 */
if (n > 0) {
ir_node *pred = get_irn_n(phi, 0);
ir_node *bound, *new_phi, **in;
ir_node *bound, *new_phi;
ir_relation relation;
bool has_confirm = false;
......@@ -4804,7 +4803,7 @@ static ir_node *transform_node_Phi(ir_node *phi)
bound = get_Confirm_bound(pred);
relation = get_Confirm_relation(pred);
NEW_ARR_A(ir_node *, in, n);
ir_node **in = ALLOCAN(ir_node*, n);
in[0] = get_Confirm_value(pred);
for (i = 1; i < n; ++i) {
......@@ -5337,9 +5336,7 @@ static ir_node *transform_node_Conv(ir_node *n)
static ir_node *transform_node_End(ir_node *n)
{
int i, j, n_keepalives = get_End_n_keepalives(n);
ir_node **in;
NEW_ARR_A(ir_node *, in, n_keepalives);
ir_node **in = ALLOCAN(ir_node*, n_keepalives);
for (i = j = 0; i < n_keepalives; ++i) {
ir_node *ka = get_End_keepalive(n, i);
......@@ -6229,7 +6226,7 @@ static ir_node *transform_node_Store(ir_node *n)
static ir_node *transform_node_Call(ir_node *call)
{
ir_node *callee = get_Call_ptr(call);
ir_node *adr, *mem, *res, *bl, **in;
ir_node *adr, *mem, *res, *bl;
ir_type *ctp, *mtp, *tp;
ir_graph *irg;
type_dbg_info *tdb;
......@@ -6264,7 +6261,7 @@ static ir_node *transform_node_Call(ir_node *call)
for (i = 0; i < n_res; ++i)
set_method_res_type(ctp, i, get_method_res_type(mtp, i));
NEW_ARR_A(ir_node *, in, n_param + 1);
ir_node **in = ALLOCAN(ir_node*, n_param+1);
/* FIXME: we don't need a new pointer type in every step */
irg = get_irn_irg(call);
......@@ -6702,10 +6699,11 @@ ir_node *optimize_node(ir_node *n)
oldn = (ir_node*)alloca(node_size);
memcpy(oldn, n, node_size);
CLONE_ARR_A(ir_node *, oldn->in, n->in);
size_t n_in = ARR_LEN(n->in);
oldn->in = ALLOCAN(ir_node*, n_in);
/* ARG, copy the in array, we need it for statistics */
memcpy(oldn->in, n->in, ARR_LEN(n->in) * sizeof(n->in[0]));
memcpy(oldn->in, n->in, n_in * sizeof(n->in[0]));
/* note the inplace edges module */
edges_node_deleted(n);
......
......@@ -25,7 +25,7 @@
#include "irmemory_t.h"
#include "irtools.h"
#include "iroptimize.h"
#include "array_t.h"
#include "array.h"
#include "pmap.h"
#include "error.h"
#include "util.h"
......@@ -728,10 +728,8 @@ static void transform_irg(compound_call_lowering_flags flags, ir_graph *irg)
ir_type *ft = get_irg_frame_type(irg);
size_t n_cr_opt = 0;
size_t j = 1;
ir_node **new_in;
cr_pair *cr_opt;
NEW_ARR_A(ir_node *, new_in, n_ress + 1);
NEW_ARR_A(cr_pair, cr_opt, n_ret_com);
ir_node **new_in = ALLOCAN(ir_node*, n_ress+1);
cr_pair *cr_opt = ALLOCAN(cr_pair, n_ret_com);
for (size_t i = 0, k = 0; i < n_ress; ++i) {
ir_node *pred = get_Return_res(ret, i);
......
......@@ -37,7 +37,7 @@
#include "pmap.h"
#include "pdeq.h"
#include "irdump.h"
#include "array_t.h"
#include "array.h"
#include "lower_dw.h"
/** A map from (op, imode, omode) to Intrinsic functions entities. */
......@@ -1676,7 +1676,6 @@ static ir_type *lower_mtp(ir_type *mtp)
*/
static void lower_Return(ir_node *node, ir_mode *mode)
{
ir_node **in;
size_t i, j, n;
int need_conv = 0;
(void) mode;
......@@ -1697,7 +1696,7 @@ static void lower_Return(ir_node *node, ir_mode *mode)
ir_type *mtp = get_entity_type(ent);
/* create a new in array */
NEW_ARR_A(ir_node *, in, get_method_n_ress(mtp) + 1);
ir_node **in = ALLOCAN(ir_node*, get_method_n_ress(mtp)+1);
j = 0;
in[j++] = get_Return_mem(node);
......
......@@ -22,7 +22,7 @@
#include "trouts.h"
#include "irverify.h"
#include "pmap.h"
#include "array_t.h"
#include "array.h"
#include "iropt_dbg.h"
#include "error.h"
#include "be.h"
......
......@@ -11,7 +11,7 @@
#include <limits.h>
#include <stdbool.h>
#include "array_t.h"
#include "array.h"
#include "ircons.h"
#include "irgopt.h"
#include "irgwalk.h"
......
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