struct hop* new_hop(struct basicblock* bb, struct ir* ir)
{
- struct hop* hop = calloc(1, sizeof *hop);
+ struct hop* hop = heap_alloc(&proc_heap, 1, sizeof(*hop));
hop->id = hop_count++;
hop->bb = bb;
hop->ir = ir;
static struct insel* new_insel(enum insel_type type)
{
- struct insel* insel = calloc(1, sizeof(*insel));
+ struct insel* insel = heap_alloc(&proc_heap, 1, sizeof(*insel));
insel->type = type;
return insel;
}
struct ir* new_ir0(int opcode, int size)
{
- struct ir* ir = calloc(sizeof(struct ir), 1);
+ struct ir* ir = calloc(1, sizeof(struct ir));
ir->id = next_id++;
ir->opcode = opcode;
ir->size = size;
#include "array.h"
#include "imap.h"
#include "pmap.h"
+#include "heap.h"
#include "diagnostics.h"
#include "astring.h"
#include "ir.h"
struct constraint* c = pmap_findleft(¤t_hop->constraints, vreg);
if (!c)
{
- c = calloc(1, sizeof(*c));
+ c = heap_alloc(&proc_heap, 1, sizeof(*c));
pmap_put(¤t_hop->constraints, vreg, c);
}
return c;
static struct insn* walk_instructions(struct burm_node* node, int goal)
{
- struct insn* insn = calloc(1, sizeof(*insn));
+ struct insn* insn = heap_alloc(&proc_heap, 1, sizeof(*insn));
int i;
insn->ir = node->ir;
static struct burm_node* build_shadow_tree(struct ir* root, struct ir* ir)
{
- struct burm_node* node = calloc(1, sizeof(*node));
+ struct burm_node* node = heap_alloc(&proc_heap, 1, sizeof(*node));
node->ir = ir;
if (ir->root == root)
while (phimap.count > 0)
{
- struct phicongruence* c = calloc(1, sizeof(*c));
+ struct phicongruence* c = heap_alloc(&proc_heap, 1, sizeof(*c));
c->id = number++;
recursively_associate_group(c, phimap.item[0].left);
update_vreg_types(c);
#include "mcg.h"
struct procedure* current_proc;
+struct heap proc_heap;
static void print_blocks(char k)
{
write_cfg_graph(proc->name);
if (dominance_dot_file)
write_dominance_graph(proc->name);
+
+ heap_free(&proc_heap);
}
/* vim: set sw=4 ts=4 expandtab : */
extern void procedure_update_bb_graph(struct procedure* proc);
extern struct procedure* current_proc;
+extern struct heap proc_heap;
#endif
struct vreg* new_vreg(void)
{
- struct vreg* vreg = calloc(1, sizeof *vreg);
+ struct vreg* vreg = heap_alloc(&proc_heap, 1, sizeof *vreg);
vreg->id = vreg_count++;
return vreg;
}
struct hreg* new_hreg(const struct burm_register_data* brd)
{
- struct hreg* hreg = calloc(1, sizeof *hreg);
+ struct hreg* hreg = heap_alloc(&proc_heap, 1, sizeof *hreg);
hreg->id = brd->id;
hreg->brd = brd;
hreg->attrs = brd->attrs;
struct hreg* new_stacked_hreg(uint32_t attrs)
{
static int hreg_count = 1;
- struct hreg* hreg = calloc(1, sizeof *hreg);
+ struct hreg* hreg = heap_alloc(&proc_heap, 1, sizeof *hreg);
hreg->id = aprintf("stacked_%d_id_%d", attrs, hreg_count++);
hreg->attrs = attrs;
hreg->is_stacked = true;
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include "heap.h"
+
+struct heap_node
+{
+ struct heap_node* next;
+ char data[1];
+};
+
+void* heap_alloc(struct heap* heap, size_t nmemb, size_t size)
+{
+ size_t bytes = nmemb * size;
+ struct heap_node* node = calloc(1, sizeof(*node) + bytes - 1);
+ if (!node)
+ return NULL;
+
+ node->next = heap->next;
+ heap->next = node;
+ return node->data;
+}
+
+void heap_free(struct heap* heap)
+{
+ while (heap->next)
+ {
+ struct heap_node* old = heap->next;
+ heap->next = old->next;
+ free(old);
+ }
+}
\ No newline at end of file
--- /dev/null
+#ifndef HEAP_H
+#define HEAP_H
+
+struct heap
+{
+ struct heap_node* next;
+};
+
+extern void* heap_alloc(struct heap* heap, size_t nmemb, size_t size);
+extern void heap_free(struct heap* heap);
+
+#endif