aboutsummaryrefslogtreecommitdiff
path: root/src/compile/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/compile/compile.c')
-rw-r--r--src/compile/compile.c67
1 files changed, 35 insertions, 32 deletions
diff --git a/src/compile/compile.c b/src/compile/compile.c
index 5432bc1..f552ae3 100644
--- a/src/compile/compile.c
+++ b/src/compile/compile.c
@@ -4,7 +4,7 @@
#define VEC_TYPE jit_operand_t
#define VEC_NAME operands
-#include "../vec.h"
+#include <conts/vec.h>
struct reloc_helper {
jit_reloc_t r;
@@ -13,11 +13,11 @@ struct reloc_helper {
#define VEC_TYPE struct reloc_helper
#define VEC_NAME relocs
-#include "../vec.h"
+#include <conts/vec.h>
#define VEC_TYPE jit_addr_t
#define VEC_NAME addrs
-#include "../vec.h"
+#include <conts/vec.h>
/* skip assertions since we know they must be valid due to type checking earlier */
static long checked_run_i(struct ejit_func *f, size_t argc, struct ejit_arg args[argc])
@@ -1880,13 +1880,11 @@ static jit_off_t type_offset(struct ejit_insn i)
static void fixup_operands(struct operands *operands, size_t fixup)
{
- foreach_vec(i, *operands) {
- jit_operand_t op = *operands_at(operands, i);
- if (op.kind != JIT_OPERAND_KIND_MEM)
+ foreach(operands, op, operands) {
+ if (op->kind != JIT_OPERAND_KIND_MEM)
continue;
- op.loc.mem.offset += fixup;
- *operands_at(operands, i) = op;
+ op->loc.mem.offset += fixup;
}
}
@@ -1922,17 +1920,22 @@ static void compile_trampoline(struct ejit_func *f, jit_state_t *j)
struct operands args = operands_create(0);
- foreach_vec(ii, f->insns) {
- struct ejit_insn i = *insns_at(&f->insns, ii);
- switch (i.op) {
+ foreach(insns, i, &f->insns) {
+ switch (i->op) {
case EJIT_OP_PARAM: {
- jit_operand_t p = jit_operand_mem(jit_abi_from(i.r1), JIT_R1, arg_offset(i));
+ jit_operand_t p = jit_operand_mem(
+ jit_abi_from(i->r1),
+ JIT_R1, arg_offset(*i));
+
operands_append(&args, p);
break;
}
case EJIT_OP_PARAM_F: {
- jit_operand_t p = jit_operand_mem(jit_abi_from(i.r1), JIT_R1, arg_offset(i));
+ jit_operand_t p = jit_operand_mem(
+ jit_abi_from(i->r1),
+ JIT_R1, arg_offset(*i));
+
operands_append(&args, p);
break;
}
@@ -1975,13 +1978,13 @@ static void resolve_top_reloc(jit_state_t *j, struct relocs *relocs, struct addr
static void resolve_relocs(jit_state_t *j, struct relocs *relocs, struct addrs *addrs, size_t ii)
{
- foreach_vec(ri, *relocs) {
- struct reloc_helper h = *relocs_at(relocs, ri);
- if (h.to != ii)
+ for (size_t ri = 0; ri < relocs_len(relocs); ++ri) {
+ struct reloc_helper *h = relocs_at(relocs, ri);
+ if (h->to != ii)
continue;
jit_addr_t a = *addrs_at(addrs, ii);
- jit_reloc_t r = h.r;
+ jit_reloc_t r = h->r;
assert(a);
jit_patch_there(j, r, a);
@@ -2052,16 +2055,16 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena,
size_t frame = jit_enter_jit_abi(j, gprs, fprs, 0);
size_t stack = jit_align_stack(j, stack_size(f));
- struct operands src = operands_create();
- struct operands dst = operands_create();
- struct operands direct = operands_create();
+ struct operands src = operands_create(f->max_args);
+ struct operands dst = operands_create(f->max_args);
+ struct operands direct = operands_create(f->max_args);
- struct relocs relocs = relocs_create();
- struct addrs addrs = addrs_create();
+ struct relocs relocs = relocs_create(labels_len(&f->labels));
+ struct addrs addrs = addrs_create(0);
addrs_reserve(&addrs, insns_len(&f->insns));
size_t label = 0;
- foreach_vec(ii, f->insns) {
+ for (size_t ii = 0; ii < insns_len(&f->insns); ++ii) {
/* if we've hit a label, add it to our vector of label addresses */
if (label < labels_len(&f->labels)) {
if (*labels_at(&f->labels, label) == ii) {
@@ -2530,7 +2533,7 @@ static size_t compile_fn_body(struct ejit_func *f, jit_state_t *j, void *arena,
/* now move args into place */
jit_operand_t args[2] = {};
- foreach_vec(oi, direct) {
+ for (size_t oi = 0; oi < operands_len(&direct); ++oi) {
args[oi] = *operands_at(&direct, oi);
}
@@ -2843,7 +2846,7 @@ struct alive_slot {
#define VEC_NAME alive
#define VEC_TYPE struct alive_slot
-#include "../vec.h"
+#include <conts/vec.h>
static int spill_cost_sort(struct alive_slot *a, struct alive_slot *b)
{
@@ -2871,7 +2874,7 @@ static void calculate_alive(struct alive *alive, size_t idx,
long max_cost_idx = -1;
size_t max_cost = 0;
long counter = 0;
- foreach_vec(ai, *alive) {
+ for (size_t ai = 0; ai < alive_len(alive); ++ai) {
/* skip oneshot */
if (ai == 0)
goto next;
@@ -2916,7 +2919,7 @@ static int gpr_dead(void *regs, size_t idx, size_t start)
static void linear_gpr_alloc(struct ejit_func *f)
{
- foreach_vec(gi, f->gpr) {
+ for (size_t gi = 0; gi < gpr_stats_len(&f->gpr); ++gi) {
gpr_stats_at(&f->gpr, gi)->rno = gi;
}
}
@@ -2934,7 +2937,7 @@ static void assign_gprs(struct ejit_func *f)
struct alive_slot a = {.r = -1, .cost = 0, .idx = 0};
alive_append(&alive, a);
- foreach_vec(gi, f->gpr) {
+ for (size_t gi = 0; gi < gpr_stats_len(&f->gpr); ++gi) {
struct gpr_stat *gpr = gpr_stats_at(&f->gpr, gi);
calculate_alive(&alive, gi,
gpr->prio, gpr->start, gpr->end, &gpr->rno,
@@ -2943,7 +2946,7 @@ static void assign_gprs(struct ejit_func *f)
/* sort so that the highest spill cost register classes are at the front and
* as such more likely to be placed in registers */
- alive_sort(&alive, (vec_comp_t)spill_cost_sort);
+ alive_sort(&alive, (alive_comp_t)spill_cost_sort);
/* update remapping info */
for(size_t i = 0; i < alive_len(&alive); ++i) {
@@ -2969,7 +2972,7 @@ static int fpr_dead(void *regs, size_t idx, size_t start)
static void linear_fpr_alloc(struct ejit_func *f)
{
- foreach_vec(fi, f->fpr) {
+ for (size_t fi = 0; fi < fpr_stats_len(&f->fpr); ++fi) {
fpr_stats_at(&f->fpr, fi)->fno = fi;
}
}
@@ -2986,7 +2989,7 @@ static void assign_fprs(struct ejit_func *f)
struct alive_slot a = {.r = -1, .cost = 0, .idx = 0};
alive_append(&alive, a);
- foreach_vec(fi, f->fpr) {
+ for (size_t fi = 0; fi < fpr_stats_len(&f->fpr); ++fi) {
struct fpr_stat *fpr = fpr_stats_at(&f->fpr, fi);
calculate_alive(&alive, fi,
fpr->prio, fpr->start, fpr->end, &fpr->fno,
@@ -2995,7 +2998,7 @@ static void assign_fprs(struct ejit_func *f)
/* sort so that the highest spill cost register classes are at the front and
* as such more likely to be placed in registers */
- alive_sort(&alive, (vec_comp_t)spill_cost_sort);
+ alive_sort(&alive, (alive_comp_t)spill_cost_sort);
/* update remapping info */
for(size_t i = 0; i < alive_len(&alive); ++i) {