changed c/malloc to xc/malloc
authorChristian Würdig <chriswue@ipd.info.uni-karlsruhe.de>
Fri, 27 Jan 2006 15:56:55 +0000 (15:56 +0000)
committerChristian Würdig <chriswue@ipd.info.uni-karlsruhe.de>
Fri, 27 Jan 2006 15:56:55 +0000 (15:56 +0000)
added alloca node

ir/be/ia32/bearch_ia32.c
ir/be/ia32/ia32_emitter.c
ir/be/ia32/ia32_gen_decls.c
ir/be/ia32/ia32_new_nodes.c
ir/be/ia32/ia32_spec.pl
ir/be/ia32/ia32_transform.c

index 7ebfa36..dd4e20c 100644 (file)
@@ -313,7 +313,7 @@ ia32_irn_ops_t ia32_irn_ops = {
 static void check_for_alloca(ir_node *irn, void *env) {
        int *has_alloca = env;
 
-       if (get_irn_opcode(irn) == iro_Alloc) {
+       if (get_irn_op(irn) == op_Alloc) {
                if (get_Alloc_where(irn) == stack_alloc) {
                        *has_alloca = 1;
                }
@@ -559,7 +559,7 @@ static const arch_code_generator_if_t ia32_code_gen_if = {
  */
 static void *ia32_cg_init(FILE *F, ir_graph *irg, const arch_env_t *arch_env) {
        ia32_isa_t      *isa = (ia32_isa_t *)arch_env->isa;
-       ia32_code_gen_t *cg  = malloc(sizeof(*cg));
+       ia32_code_gen_t *cg  = xmalloc(sizeof(*cg));
 
        cg->impl       = &ia32_code_gen_if;
        cg->irg        = irg;
@@ -599,7 +599,7 @@ static void *ia32_cg_init(FILE *F, ir_graph *irg, const arch_env_t *arch_env) {
  */
 static void *ia32_init(void) {
        static int inited = 0;
-       ia32_isa_t *isa   = malloc(sizeof(*isa));
+       ia32_isa_t *isa   = xmalloc(sizeof(*isa));
 
        isa->impl = &ia32_isa_if;
 
index e668f91..6bf0f25 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <limits.h>
 
+#include "xmalloc.h"
 #include "tv.h"
 #include "iredges.h"
 #include "debug.h"
@@ -44,7 +45,7 @@ const char *node_const_to_str(ir_node *n) {
        tarval *tv = get_ia32_Immop_tarval(n);
 
        if (tv) {
-               buf = malloc(SNPRINTF_BUF_LEN);
+               buf = xmalloc(SNPRINTF_BUF_LEN);
                tarval_snprintf(buf, SNPRINTF_BUF_LEN, tv);
                return buf;
        }
@@ -63,7 +64,7 @@ char *node_offset_to_str(ir_node *n) {
        tarval *tv = get_ia32_am_offs(n);
 
        if (tv) {
-               buf = malloc(SNPRINTF_BUF_LEN);
+               buf = xmalloc(SNPRINTF_BUF_LEN);
                tarval_snprintf(buf, SNPRINTF_BUF_LEN, tv);
                return buf;
        }
@@ -474,11 +475,11 @@ void emit_ia32_SwitchJmp(const ir_node *irn, emit_env_t *emit_env) {
        FILE               *F   = emit_env->out;
 
        /* fill the table structure */
-       tbl.label        = malloc(SNPRINTF_BUF_LEN);
+       tbl.label        = xmalloc(SNPRINTF_BUF_LEN);
        tbl.label        = get_unique_label(tbl.label, SNPRINTF_BUF_LEN, "JMPTBL_");
        tbl.defProj      = NULL;
        tbl.num_branches = get_irn_n_edges(irn);
-       tbl.branches     = calloc(tbl.num_branches, sizeof(tbl.branches[0]));
+       tbl.branches     = xcalloc(tbl.num_branches, sizeof(tbl.branches[0]));
        tbl.min_value    = INT_MAX;
        tbl.max_value    = INT_MIN;
 
index 3b80c14..626215c 100644 (file)
 #include <ctype.h>
 #include <assert.h>
 
+#include "xmalloc.h"
 #include <obstack.h>
 
 #ifdef obstack_chunk_alloc
 # undef obstack_chunk_alloc
-# define obstack_chunk_alloc malloc
+# define obstack_chunk_alloc xmalloc
 #else
-# define obstack_chunk_alloc malloc
+# define obstack_chunk_alloc xmalloc
 # define obstack_chunk_free free
 #endif
 
@@ -437,7 +438,7 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
            * size should be equal or bigger the number of fields
            */
           type_size = get_type_size_bytes(ty);
-          vals      = calloc(type_size, sizeof(*vals));
+          vals      = xcalloc(type_size, sizeof(*vals));
 
           /* collect the values and store them at the offsets */
           for(i = 0; i < get_compound_ent_n_values(ent); ++i) {
@@ -448,7 +449,7 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
 
             /* get the access path to the costant value */
             graph_length = get_compound_graph_path_length(path);
-            ai = calloc(graph_length, sizeof(struct arr_info));
+            ai = xcalloc(graph_length, sizeof(struct arr_info));
 
             /* We wanna know how many arrays are on the path to the entity. We also have to know how
              * many elements each array holds to calculate the offset for the entity. */
index e5c0d31..fe05c63 100644 (file)
@@ -552,7 +552,7 @@ void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
        na->tv = ca->tv;
 
        if (ca->old_ir) {
-               na->old_ir = calloc(1, sizeof(*(ca->old_ir)));
+               na->old_ir = xcalloc(1, sizeof(*(ca->old_ir)));
                memcpy(na->old_ir, ca->old_ir, sizeof(*(ca->old_ir)));
        }
        else {
@@ -576,7 +576,7 @@ void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
                case iro_SymConst:
                        attr->tp     = asmop_SymConst;
                        attr->tv     = NULL;
-                       attr->old_ir = calloc(1, sizeof(*cnst));
+                       attr->old_ir = xcalloc(1, sizeof(*cnst));
                        memcpy(attr->old_ir, cnst, sizeof(*cnst));
                        break;
                case iro_Unknown:
index 5e0a7ef..790f757 100644 (file)
@@ -747,7 +747,24 @@ $arch = "ia32";
 "  if (!op_ia32_Return) assert(0);
   return new_ir_node(db, irg, block, op_ia32_Return, mode_X, n, in);
 "
-}
+},
+
+# M/Alloc
+
+"Alloca" => {
+  "op_flags" => "L|F",
+  "state"    => "pinned",
+  "arity"    => "2",
+  "comment"  => "construct Alloca: allocate memory on Stack",
+  "reg_req"  => { "in" => [ "general_purpose" ], "out" => [ "general_purpose" ] }
+},
 
+"Alloca_i" => {
+  "op_flags" => "L|F",
+  "state"    => "pinned",
+  "arity"    => "1",
+  "comment"  => "construct Alloca: allocate memory on Stack",
+  "reg_req"  => { "out" => [ "general_purpose" ] }
+}
 
 ); # end of %nodes
index aba81c4..9bbe585 100644 (file)
@@ -1034,14 +1034,14 @@ static ir_node *gen_Call(ia32_transform_env_t *env) {
 
        /* do we need to pass arguments on stack? */
        if (biggest_n + 1 < n)
-               stack_param = calloc(n - biggest_n - 1, sizeof(ir_node *));
+               stack_param = xcalloc(n - biggest_n - 1, sizeof(ir_node *));
 
        /* we need at least one in, either for the stack params or the call_Mem */
        n_new_call_in = biggest_n + 2;
 
        /* the call has one IN for all stack parameter and one IN for each reg param */
-       in     = calloc(n_new_call_in, sizeof(ir_node *));
-       in_req = calloc(n_new_call_in, sizeof(arch_register_req_t *));
+       in     = xcalloc(n_new_call_in, sizeof(ir_node *));
+       in_req = xcalloc(n_new_call_in, sizeof(arch_register_req_t *));
 
        /* loop over all parameters and set the register requirements */
        for (i = 0; i <= biggest_n && (cc & cc_reg_param); i++) {
@@ -1093,10 +1093,10 @@ static ir_node *gen_Call(ia32_transform_env_t *env) {
        /* set register requirements for in and out */
        attr             = get_ia32_attr(new_call);
        attr->in_req     = in_req;
-       attr->out_req    = calloc(2, sizeof(ia32_register_req_t *));
+       attr->out_req    = xcalloc(2, sizeof(ia32_register_req_t *));
        attr->out_req[0] = &ia32_default_req_ia32_general_purpose_eax;
        attr->out_req[1] = &ia32_default_req_ia32_general_purpose_edx;
-       attr->slots      = calloc(2, sizeof(arch_register_t *));
+       attr->slots      = xcalloc(2, sizeof(arch_register_t *));
 
        /* stack parameter has no OUT register */
        attr->in_req[n_new_call_in - 1] = &ia32_default_req_none;
@@ -1195,14 +1195,14 @@ static ir_node *gen_Proj_Start(ia32_transform_env_t *env, ir_node *proj, ir_node
                        n = get_irn_n_edges(proj);
 
                        /* Allocate memory for all non variadic parameters in advance to be on the save side */
-                       env->cg->reg_param_req = calloc(get_method_n_params(tp), sizeof(ia32_register_req_t *));
+                       env->cg->reg_param_req = xcalloc(get_method_n_params(tp), sizeof(ia32_register_req_t *));
 
                        /* we are done here when there are no parameters */
                        if (n < 1)
                                break;
 
                        /* temporary remember all proj arg x */
-                       projargs = calloc(n, sizeof(ir_node *));
+                       projargs = xcalloc(n, sizeof(ir_node *));
 
                        i = 0;
                        foreach_out_edge((const ir_node *)proj, edge) {
@@ -1285,6 +1285,36 @@ static ir_node *gen_Proj(ia32_transform_env_t *env) {
 
 
 
+/**
+ * Transforms an Alloc node into either ia32_Alloca or ia32_Malloc.
+ */
+static ir_node *gen_Alloc(ia32_transform_env_t *env) {
+       dbg_info *dbg   = env->dbg;
+       ir_graph *irg   = env->irg;
+       ir_node  *block = env->block;
+       ir_node  *irn   = env->irn;
+       ir_mode  *mode  = env->mode;
+       ir_node  *size  = get_Alloc_size(irn);
+       ir_node  *mem   = get_Alloc_mem(irn);
+       ir_node  *res;
+
+       if (get_Alloc_where(irn) == stack_alloc) {
+               if (is_ia32_Const(size)) {
+                       res = new_rd_ia32_Alloca_i(dbg, irg, block, mem, mode);
+                       set_ia32_Immop_attr(res, size);
+               }
+               else {
+                       res = new_rd_ia32_Alloca(dbg, irg, block, size, mem, mode);
+               }
+       }
+       else {
+               assert(0 && "malloc should be already lowered");
+               res = NULL;
+       }
+
+       return res;
+}
+
 /*********************************************************
  *                  _             _      _
  *                 (_)           | |    (_)
@@ -1357,8 +1387,8 @@ void ia32_transform_node(ir_node *node, void *env) {
                GEN(Store);
                GEN(Call);
                GEN(Cond);
-
                GEN(Proj);
+               GEN(Alloc);
 
                IGN(Block);
                IGN(Start);
@@ -1373,7 +1403,6 @@ void ia32_transform_node(ir_node *node, void *env) {
                IGN(Const);
                IGN(SymConst);
 
-               BAD(Alloc);
                BAD(Raise);
                BAD(Sel);
                BAD(InstOf);