Skip to content

Commit

Permalink
update tb
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawSumma committed May 4, 2024
1 parent 8cf308a commit 23ddc9c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 42 deletions.
4 changes: 0 additions & 4 deletions main/minivm.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ int main(int argc, char **argv) {
config->dump_tb = true;
} else if (!strcmp(arg, "opt")) {
config->dump_tb_opt = true;
} else if (!strcmp(arg, "tb-dot")) {
config->dump_tb_dot = true;
} else if (!strcmp(arg, "opt-dot")) {
config->dump_tb_opt_dot = true;
} else if (!strcmp(arg, "asm")) {
config->dump_asm = true;
} else if (!strcmp(arg, "args")) {
Expand Down
1 change: 0 additions & 1 deletion vendor/llvm-box
Submodule llvm-box deleted from ee28d2
5 changes: 3 additions & 2 deletions vm/backend/tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ vm_std_value_t vm_tb_run_repl(vm_config_t *config, vm_block_t *entry, vm_blocks_

TB_PrototypeParam proto_params[2] = {{TB_TYPE_PTR}, {TB_TYPE_PTR}};
TB_Function *fun = tb_function_create(mod, -1, "caller", TB_LINKAGE_PUBLIC);
tb_function_set_arenas(fun, tmp_arena, tmp_arena);
TB_FunctionPrototype *proto = tb_prototype_create(mod, VM_TB_CC, 2, proto_params, 0, NULL, false);
tb_function_set_prototype(fun, -1, proto, NULL);
tb_function_set_prototype(fun, -1, proto);

// tb_inst_debugbreak(fun);
TB_MultiOutput out = tb_inst_call(fun, call_proto, tb_inst_param(fun, 1), 0, NULL);
Expand All @@ -62,7 +63,7 @@ vm_std_value_t vm_tb_run_repl(vm_config_t *config, vm_block_t *entry, vm_blocks_
tb_inst_ret(fun, 0, NULL);

// compile it
tb_codegen(fun, worklist, tmp_arena, code_arena, tmp_arena, NULL, false);
tb_codegen(fun, worklist, code_arena, NULL, false);

caller = tb_jit_place_function(jit, fun);

Expand Down
24 changes: 12 additions & 12 deletions vm/backend/tb_dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,12 @@ TB_Node *vm_tb_dyn_block(vm_tb_dyn_state_t *state, vm_block_t *block) {
{
tb_inst_set_control(state->func, is_ffi);

TB_Node *call_arg = tb_inst_local(state->func, sizeof(vm_std_value_t) * (num_args / 2), 8);
TB_Node *call_arg;
if (num_args == 0) {
call_arg = tb_inst_local(state->func, sizeof(vm_std_value_t) * (num_args / 2), 8);
} else {
call_arg = tb_inst_local(state->func, sizeof(vm_std_value_t), 8);
}

for (size_t i = 1; branch.args[i].type != VM_ARG_NONE; i++) {
TB_Node *head = tb_inst_member_access(state->func, call_arg, sizeof(vm_std_value_t) * (i - 1));
Expand Down Expand Up @@ -1041,7 +1046,7 @@ void vm_tb_dyn_func(vm_tb_dyn_state_t *state, TB_Function *xfunc, vm_block_t *en
{VM_TB_TYPE_TAG},
};
TB_FunctionPrototype *proto = tb_prototype_create(state->mod, VM_TB_CC, num_params, param_types, num_returns, return_types, false);
tb_function_set_prototype(state->func, -1, proto, NULL);
tb_function_set_prototype(state->func, -1, proto);

TB_Node *compiled_start = tb_inst_region(state->func);

Expand Down Expand Up @@ -1165,6 +1170,7 @@ vm_tb_dyn_func_t *vm_tb_dyn_comp(vm_tb_dyn_state_t *state, vm_block_t *entry) {
char buf[64];
snprintf(buf, 63, "vm_block_func_%zu", block_num);
TB_Function *cur = tb_function_create(state->mod, -1, buf, TB_LINKAGE_PUBLIC);
tb_function_set_arenas(cur, tmp_arena, ir_arena);
if (block == entry) {
snprintf(entry_buf, 63, "%s", buf);
entry_func = cur;
Expand Down Expand Up @@ -1192,24 +1198,18 @@ vm_tb_dyn_func_t *vm_tb_dyn_comp(vm_tb_dyn_state_t *state, vm_block_t *entry) {
tb_print(state->funcs[block_num], tmp_arena);
fflush(stdout);
}

if (state->config->tb_opt) {
tb_opt(state->funcs[block_num], worklist, ir_arena, tmp_arena, false);
tb_opt(state->funcs[block_num], worklist, false);

if (state->config->dump_tb_opt) {
fprintf(stdout, "\n--- opt tb ---\n");
tb_print(state->funcs[block_num], tmp_arena);
fflush(stdout);
}
if (state->config->dump_tb_dot) {
fprintf(stdout, "\n--- opt dot ---\n");
tb_print_dot(state->funcs[block_num], tb_default_print_callback, stdout);
fflush(stdout);
}
}
}
}


void *ret = NULL;
switch (state->config->target) {
Expand Down Expand Up @@ -1319,10 +1319,10 @@ vm_tb_dyn_func_t *vm_tb_dyn_comp(vm_tb_dyn_state_t *state, vm_block_t *entry) {
TB_Function *func = state->funcs[block_num];
if (func != NULL) {
if (state->config->dump_asm) {
TB_FunctionOutput *out = tb_codegen(func, worklist, ir_arena, tmp_arena, code_arena, &features, true);
TB_FunctionOutput *out = tb_codegen(func, worklist, code_arena, &features, true);
tb_output_print_asm(out, stdout);
} else {
tb_codegen(func, worklist, ir_arena, tmp_arena, code_arena, &features, false);
tb_codegen(func, worklist, code_arena, &features, false);
}
}
}
Expand Down
23 changes: 7 additions & 16 deletions vm/backend/tb_ver.h
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@ static void *vm_tb_ver_rfunc_comp(vm_rblock_t *rblock) {
snprintf(name, 23, "block_unk_%zu", comps++);
}
state->fun = tb_function_create(state->module, -1, name, TB_LINKAGE_PUBLIC);
tb_function_set_arenas(state->fun, state->tmp_arena, state->ir_arena);

if (block == NULL) {
TB_PrototypeParam proto_rets[2] = {
Expand All @@ -1728,7 +1729,7 @@ static void *vm_tb_ver_rfunc_comp(vm_rblock_t *rblock) {
};

TB_FunctionPrototype *proto = tb_prototype_create(state->module, VM_TB_CC, 0, NULL, 2, proto_rets, false);
tb_function_set_prototype(state->fun, -1, proto, state->ir_arena);
tb_function_set_prototype(state->fun, -1, proto);

vm_tb_ver_func_report_error(state, "internal: block == NULL");
} else {
Expand All @@ -1748,7 +1749,7 @@ static void *vm_tb_ver_rfunc_comp(vm_rblock_t *rblock) {
TB_FunctionPrototype *proto = tb_prototype_create(state->module, VM_TB_CC, block->nargs, proto_args, 2, proto_rets, false);
vm_free(proto_args);

tb_function_set_prototype(state->fun, -1, proto, state->ir_arena);
tb_function_set_prototype(state->fun, -1, proto);

if (block != NULL) {
for (size_t i = 0; i < block->nargs; i++) {
Expand Down Expand Up @@ -1823,24 +1824,14 @@ static void *vm_tb_ver_rfunc_comp(vm_rblock_t *rblock) {
tb_print(f, state->tmp_arena);
fflush(stdout);
}
if (state->config->dump_tb_dot) {
fprintf(stdout, "\n--- tb dot ---\n");
tb_print_dot(f, tb_default_print_callback, stdout);
fflush(stdout);
}
if (state->config->tb_opt) {
tb_opt(f, worklist, state->ir_arena, state->tmp_arena, false);
tb_opt(f, worklist, false);

if (state->config->dump_tb_opt) {
fprintf(stdout, "\n--- opt tb ---\n");
tb_print(f, state->tmp_arena);
fflush(stdout);
}
if (state->config->dump_tb_dot) {
fprintf(stdout, "\n--- opt dot ---\n");
tb_print_dot(f, tb_default_print_callback, stdout);
fflush(stdout);
}
}
#endif

Expand Down Expand Up @@ -1917,14 +1908,14 @@ static void *vm_tb_ver_rfunc_comp(vm_rblock_t *rblock) {
TB_FeatureSet features = (TB_FeatureSet){};
#if VM_USE_DUMP
if (state->config->dump_asm) {
TB_FunctionOutput *out = tb_codegen(f, worklist, state->ir_arena, state->tmp_arena, state->code_arena, &features, true);
TB_FunctionOutput *out = tb_codegen(f, worklist, state->code_arena, &features, true);
fprintf(stdout, "\n--- x86asm ---\n");
tb_output_print_asm(out, stdout);
} else {
tb_codegen(f, worklist, state->ir_arena, state->tmp_arena, state->code_arena, &features, false);
tb_codegen(f, worklist, state->code_arena, &features, false);
}
#else
tb_codegen(f, worklist, state->ir_arena, state->tmp_arena, state->code_arena, &features, false);
tb_codegen(f, worklist, state->code_arena, &features, false);
#endif

void *code = tb_jit_place_function(state->jit, f);
Expand Down
2 changes: 0 additions & 2 deletions vm/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ struct vm_config_t {
bool dump_ver : 1;
bool dump_tb : 1;
bool dump_tb_opt : 1;
bool dump_tb_dot : 1;
bool dump_tb_opt_dot : 1;
bool dump_asm : 1;
bool dump_args : 1;
bool dump_time : 1;
Expand Down
4 changes: 0 additions & 4 deletions vm/lua/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ void vm_lang_lua_repl_table_get_config(vm_table_t *table, vm_config_t *config) {
config->dump_ver = vm_lang_lua_repl_table_get_bool(dump, "ver");
config->dump_tb = vm_lang_lua_repl_table_get_bool(dump, "tb");
config->dump_tb_opt = vm_lang_lua_repl_table_get_bool(dump, "tb_opt");
config->dump_tb_dot = vm_lang_lua_repl_table_get_bool(dump, "tb_dot");
config->dump_tb_opt_dot = vm_lang_lua_repl_table_get_bool(dump, "tb_opt_dot");
config->dump_asm = vm_lang_lua_repl_table_get_bool(dump, "asm");
config->dump_args = vm_lang_lua_repl_table_get_bool(dump, "args");
config->dump_time = vm_lang_lua_repl_table_get_bool(dump, "time");
Expand All @@ -59,8 +57,6 @@ void vm_lang_lua_repl_table_set_config(vm_table_t *table, vm_config_t *config) {
VM_TABLE_SET(dump, str, "ver", b, config->dump_ver);
VM_TABLE_SET(dump, str, "tb", b, config->dump_tb);
VM_TABLE_SET(dump, str, "tb_opt", b, config->dump_tb_opt);
VM_TABLE_SET(dump, str, "tb_dot", b, config->dump_tb_dot);
VM_TABLE_SET(dump, str, "tb_opt_dot", b, config->dump_tb_opt_dot);
VM_TABLE_SET(dump, str, "asm", b, config->dump_asm);
VM_TABLE_SET(dump, str, "args", b, config->dump_args);
VM_TABLE_SET(dump, str, "time", b, config->dump_time);
Expand Down

0 comments on commit 23ddc9c

Please sign in to comment.