fix: pointer alias BUG
authoryu.dongliang <18588496441@163.com>
Sat, 22 Apr 2023 14:25:40 +0000 (22:25 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 22 Apr 2023 14:25:40 +0000 (22:25 +0800)
core/scf_optimizer_generate_loads_saves.c
core/scf_optimizer_pointer_alias.c
core/scf_optimizer_pointer_aliases.c
parse/main.c

index ce60ac9ff49e8ea19a762972bf57e73cef2ce975..825572a87e2f46b1a0111ae116d311d36db764bb 100644 (file)
@@ -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) {
index 13dd2c40903254a6b843962b2acc13ccfcee663b..ae24616668dbd9f7e78d46e29b7de52952a49dc5 100644 (file)
@@ -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;
index adb4477c930a23d293981a78385f2120c79e42bc..94da27af1cf892df5057b7d3e957d4d74801f5f3 100644 (file)
@@ -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)
index 93e2c1a914ce5b7c9037f2a59a78ad8cd57cb93b..b4aedef574987b1333f16e3b03dbb6232c1aa793 100644 (file)
@@ -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[])