From: yu.dongliang <18588496441@163.com> Date: Sat, 22 Apr 2023 14:25:40 +0000 (+0800) Subject: fix: pointer alias BUG X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=015bda09784c7cfaefac83f9b9a1743308ba51f9;p=scf.git fix: pointer alias BUG --- diff --git a/core/scf_optimizer_generate_loads_saves.c b/core/scf_optimizer_generate_loads_saves.c index ce60ac9..825572a 100644 --- a/core/scf_optimizer_generate_loads_saves.c +++ b/core/scf_optimizer_generate_loads_saves.c @@ -100,6 +100,11 @@ static int _optimize_generate_loads_saves(scf_ast_t* ast, scf_function_t* f, scf for (i = 0; i < bb->dn_resaves->size; i++) { dn = bb->dn_resaves->data[i]; SCF_OPTIMIZER_SAVE(SCF_OP_3AC_RESAVE, &bb->code_list_head); + + if (bb->cmp_flag) { + scf_list_del(&save->list); + scf_list_add_front(&bb->code_list_head, &save->list); + } } if (bb->auto_ref_flag || bb->auto_free_flag) { diff --git a/core/scf_optimizer_pointer_alias.c b/core/scf_optimizer_pointer_alias.c index 13dd2c4..ae24616 100644 --- a/core/scf_optimizer_pointer_alias.c +++ b/core/scf_optimizer_pointer_alias.c @@ -359,7 +359,7 @@ static int __optimize_alias_bb(scf_list_t** pend, scf_list_t* start, scf_basic_b flag += ret; } else if (SCF_OP_DEREFERENCE == c->op->type) { -#if 0 +#if 1 assert(c->dsts && 1 == c->dsts->size); dst = c->dsts->data[0]; dn_dereference = dst->dag_node; diff --git a/core/scf_optimizer_pointer_aliases.c b/core/scf_optimizer_pointer_aliases.c index adb4477..94da27a 100644 --- a/core/scf_optimizer_pointer_aliases.c +++ b/core/scf_optimizer_pointer_aliases.c @@ -128,44 +128,6 @@ static int _bb_next_find_loads(scf_basic_block_t* bb, void* data, scf_vector_t* return count; } -static void _bb_info_print_list(scf_list_t* h) -{ - scf_list_t* l; - scf_list_t* l2; - scf_basic_block_t* bb; - - for (l = scf_list_head(h); l != scf_list_sentinel(h); l = scf_list_next(l)) { - - bb = scf_list_data(l, scf_basic_block_t, list); - - for (l2 = scf_list_head(&bb->code_list_head); l2 != scf_list_sentinel(&bb->code_list_head); - l2 = scf_list_next(l2)) { - - scf_3ac_code_t* c = scf_list_data(l2, scf_3ac_code_t, list); - - scf_3ac_code_print(c, NULL); - } - - int j; - for (j = 0; j < bb->entry_dn_aliases->size; j++) { - - scf_dag_node_t* dn = bb->entry_dn_aliases->data[j]; - scf_variable_t* v = dn->var; - - scf_logw("pointer aliases entry: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); - } - - for (j = 0; j < bb->exit_dn_aliases->size; j++) { - - scf_dag_node_t* dn = bb->exit_dn_aliases->data[j]; - scf_variable_t* v = dn->var; - - scf_logw("pointer aliases exit: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); - } - printf("\n"); - } -} - static int _optimize_pointer_aliases(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions) { if (!f || !bb_list_head) diff --git a/parse/main.c b/parse/main.c index 93e2c1a..b4aedef 100644 --- a/parse/main.c +++ b/parse/main.c @@ -31,9 +31,7 @@ void usage(char* path) { fprintf(stderr, "Usage: %s [-c] [-a arch] [-o out] src0 [src1]\n\n", path); fprintf(stderr, "-c: only compile, not link\n"); - fprintf(stderr, "-a: select cpu arch (x64 or arm64 or naja), default is x64\n\n"); - fprintf(stderr, "naja is a bytecode designed by me, so that a script language can be developed based on scf framework.\n"); - fprintf(stderr, "naja is compiled & linked to ELF, and run by nvm in 'scf/vm' dir.\n"); + fprintf(stderr, "-a: select cpu arch (x64 or arm64), default is x64\n"); } int main(int argc, char* argv[])