Skip to content

Commit

Permalink
vm_type_t: part 4
Browse files Browse the repository at this point in the history
Signed-off-by: Shaw Summa <[email protected]>
  • Loading branch information
ShawSumma committed Feb 26, 2024
1 parent ee6bb37 commit 14f5c90
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions vendor/common/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#endif

enum {
TB_ARENA_SMALL_CHUNK_SIZE = 4 * 1024,
TB_ARENA_MEDIUM_CHUNK_SIZE = 512 * 1024,
TB_ARENA_LARGE_CHUNK_SIZE = 4 * 1024 * 1024,
TB_ARENA_SMALL_CHUNK_SIZE = 16 * 1024,
TB_ARENA_MEDIUM_CHUNK_SIZE = 4 * 1024 * 1024,
TB_ARENA_LARGE_CHUNK_SIZE = 16 * 1024 * 1024,

TB_ARENA_ALIGNMENT = 16,
};
Expand Down
32 changes: 21 additions & 11 deletions vm/backend/tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ TB_Node *vm_tb_ptr_name(vm_tb_state_t *state, const char *name, const void *valu

TB_Node *vm_tb_make_type(vm_tb_state_t *state, vm_type_t type) {
switch (vm_type_tag(type)) {
case VM_TAG_UNK: {
return vm_tb_ptr_name(state, "VM_TYPE_UNK", VM_TYPE_UNK);
}
case VM_TAG_NIL: {
return vm_tb_ptr_name(state, "VM_TYPE_NIL", VM_TYPE_NIL);
}
Expand Down Expand Up @@ -816,7 +819,7 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
vm_arg_t arg = branch.args[i];
TB_Node *head = tb_inst_member_access(state->fun, call_arg, sizeof(vm_std_value_t) * (i - 1));
vm_type_t tag = vm_arg_to_tag(arg);
if (vm_type_eq(tag, VM_TYPE_NIL)) {
if (!vm_type_eq(tag, VM_TYPE_NIL)) {
tb_inst_store(
state->fun,
VM_TB_TYPE_VALUE,
Expand All @@ -830,7 +833,7 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
state->fun,
TB_TYPE_PTR,
tb_inst_member_access(state->fun, head, offsetof(vm_std_value_t, tag)),
vm_tb_make_type(state->fun, tag),
vm_tb_make_type(state, tag),
8,
false
);
Expand All @@ -842,7 +845,7 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
state->fun,
TB_TYPE_PTR,
tb_inst_member_access(state->fun, end_head, offsetof(vm_std_value_t, tag)),
vm_tb_make_type(state->fun, VM_TYPE_UNK),
vm_tb_make_type(state, VM_TYPE_UNK),
4,
false
);
Expand Down Expand Up @@ -1205,6 +1208,14 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
}
}

TB_Node *val_tag_tag = tb_inst_load(
state->fun,
TB_TYPE_I8,
tb_inst_member_access(state->fun, val_tag, offsetof(vm_type_value_t, tag)),
1,
false
);

size_t next_nargs = branch.targets[0]->nargs;

// for (size_t argno = 0; argno < next_nargs; argno++) {
Expand All @@ -1216,7 +1227,7 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
{
TB_Node *report_err = tb_inst_region(state->fun);
TB_Node *after_err_check = tb_inst_region(state->fun);
TB_Node *is_err = tb_inst_cmp_eq(state->fun, val_tag, vm_tb_make_type(state, VM_TYPE_ERROR));
TB_Node *is_err = tb_inst_cmp_eq(state->fun, val_tag_tag, tb_inst_uint(state->fun, TB_TYPE_I8, VM_TAG_ERROR));
tb_inst_if(state->fun, is_err, report_err, after_err_check);
tb_inst_set_control(state->fun, report_err);
TB_Node *ret_args[2] = {
Expand Down Expand Up @@ -1259,7 +1270,7 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
TB_Node *func_ref = tb_inst_array_access(
state->fun,
vm_tb_ptr_name(state, "<rtargets>", mem),
val_tag,
val_tag_tag,
sizeof(void *)
);
TB_Node *func = tb_inst_load(
Expand Down Expand Up @@ -1301,7 +1312,7 @@ void vm_tb_func_body_once_as(vm_tb_state_t *state, TB_Node **regs, vm_block_t *b
tb_inst_array_access(
state->fun,
vm_tb_ptr_name(state, "<rtargets>", &block->branch.rtargets[0]),
val_tag,
val_tag_tag,
sizeof(vm_rblock_t *)
),
1,
Expand Down Expand Up @@ -1463,8 +1474,8 @@ void vm_tb_new_module(vm_tb_state_t *state) {
tb_symbol_bind_ptr(state->vm_table_get_pair, (void *)&vm_table_get_pair);
tb_symbol_bind_ptr(state->vm_tb_print, (void *)&vm_tb_print);

state->arena = tb_arena_create(1 << 16);
state->jit = tb_jit_begin(state->module, 1 << 16);
state->arena = tb_arena_create(1 << 20);
state->jit = tb_jit_begin(state->module, 1 << 20);

// on windows we don't have access to multiple returns from C so we'll
// just make a dumb caller for such a pattern
Expand Down Expand Up @@ -1622,7 +1633,7 @@ void *vm_tb_rfunc_comp(vm_rblock_t *rblock) {
if (arg.type == VM_ARG_REG && vm_type_eq(rblock->regs->tags[arg.reg], VM_TYPE_ERROR)) {
TB_Node *rets[2];
rets[0] = tb_inst_param(state->fun, i);
rets[1] = vm_tb_make_type(state->fun, VM_TYPE_ERROR);
rets[1] = vm_tb_make_type(state, VM_TYPE_ERROR);
tb_inst_ret(state->fun, 2, rets);
block = NULL;
}
Expand Down Expand Up @@ -1668,7 +1679,6 @@ void *vm_tb_rfunc_comp(vm_rblock_t *rblock) {
}
}

TB_Arena *parena = state->arena;
TB_Passes *passes = tb_pass_enter(state->fun, tb_function_get_arena(state->fun));
#if VM_USE_DUMP
if (state->config->dump_tb) {
Expand Down Expand Up @@ -1802,7 +1812,7 @@ void vm_tcc_error_func(void *user, const char *msg) {
#endif

void vm_tb_rblock_del(vm_rblock_t *rblock) {
TB_JIT *jit = rblock->jit;
// TB_JIT *jit = rblock->jit;
}

void *vm_tb_full_comp(vm_tb_state_t *state, vm_block_t *block) {
Expand Down
1 change: 0 additions & 1 deletion vm/ir/rblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ vm_block_t *vm_rblock_version(vm_blocks_t *blocks, vm_rblock_t *rblock) {
ret->args[i].reg_tag = regs->tags[ret->args[i].reg];
}
}
ret:;
vm_free(regs->tags);
vm_free(regs);
return ret;
Expand Down
4 changes: 2 additions & 2 deletions vm/ir/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef struct vm_type_value_t vm_type_value_t;
typedef const vm_type_value_t *vm_type_t;

struct vm_type_value_t {
vm_tag_t tag: 8;
uint8_t tag;
};
extern const vm_type_value_t vm_type_base[VM_TAG_MAX];

Expand Down Expand Up @@ -64,7 +64,7 @@ static uint32_t vm_type_tag(vm_type_t type) {
return type->tag;
}

static bool vm_type_eq(vm_type_t a, vm_type_t b) {
static inline bool vm_type_eq(vm_type_t a, vm_type_t b) {
if (a == NULL || b == NULL) {
return a == NULL && b == NULL;
}
Expand Down

0 comments on commit 14f5c90

Please sign in to comment.