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;
}
*/
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;
*/
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;
#include <limits.h>
+#include "xmalloc.h"
#include "tv.h"
#include "iredges.h"
#include "debug.h"
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;
}
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;
}
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;
#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
* 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) {
/* 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. */
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 {
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:
" 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
/* 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++) {
/* 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;
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) {
+/**
+ * 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;
+}
+
/*********************************************************
* _ _ _
* (_) | | (_)
GEN(Store);
GEN(Call);
GEN(Cond);
-
GEN(Proj);
+ GEN(Alloc);
IGN(Block);
IGN(Start);
IGN(Const);
IGN(SymConst);
- BAD(Alloc);
BAD(Raise);
BAD(Sel);
BAD(InstOf);