From: yu.dongliang <18588496441@163.com> Date: Tue, 1 Oct 2024 04:25:04 +0000 (+0800) Subject: delete ../core/scf_optimizer_dominators_reverse.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=6d8702ace664af692e647ccf56879eb15e6db1fa;p=scf.git delete ../core/scf_optimizer_dominators_reverse.c --- diff --git a/core/scf_basic_block.c b/core/scf_basic_block.c index e58e973..786e3b8 100644 --- a/core/scf_basic_block.c +++ b/core/scf_basic_block.c @@ -243,170 +243,161 @@ void scf_bb_group_print(scf_bb_group_t* bbg) void scf_basic_block_print_list(scf_list_t* h) { - scf_list_t* l; + if (scf_list_empty(h)) + return; - if (!scf_list_empty(h)) { - - scf_basic_block_t* bb2; - scf_basic_block_t* last_bb = scf_list_data(scf_list_tail(h), scf_basic_block_t, list); - scf_list_t* sentinel = scf_list_sentinel(&last_bb->code_list_head); + scf_dn_status_t* ds; + scf_dag_node_t* dn; + scf_variable_t* v; - for (l = scf_list_head(h); l != scf_list_sentinel(h); l = scf_list_next(l)) { + scf_basic_block_t* bb; + scf_basic_block_t* bb2; + scf_basic_block_t* last_bb = scf_list_data(scf_list_tail(h), scf_basic_block_t, list); + scf_list_t* sentinel = scf_list_sentinel(&last_bb->code_list_head); + scf_list_t* l; - scf_basic_block_t* bb = scf_list_data(l, scf_basic_block_t, list); + 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); - printf("\033[33mbasic_block: %p, index: %d, dfo_normal: %d, cmp_flag: %d, call_flag: %d, group: %d, loop: %d, dereference_flag: %d, ret_flag: %d\033[0m\n", - bb, bb->index, bb->dfo_normal, bb->cmp_flag, bb->call_flag, bb->group_flag, bb->loop_flag, bb->dereference_flag, bb->ret_flag); + printf("\033[33mbasic_block: %p, index: %d, dfo: %d, cmp_flag: %d, call_flag: %d, group: %d, loop: %d, dereference_flag: %d, ret_flag: %d\033[0m\n", + bb, bb->index, bb->dfo, bb->cmp_flag, bb->call_flag, bb->group_flag, bb->loop_flag, bb->dereference_flag, bb->ret_flag); - scf_basic_block_print(bb, sentinel); + scf_basic_block_print(bb, sentinel); - printf("\n"); - int i; - if (bb->prevs) { - for (i = 0; i < bb->prevs->size; i++) { - bb2 = bb->prevs->data[i]; + printf("\n"); + int i; + if (bb->prevs) { + for (i = 0; i < bb->prevs->size; i++) { + bb2 = bb->prevs->data[i]; - printf("prev : %p, index: %d\n", bb2, bb2->index); - } + printf("prev : %p, index: %d\n", bb2, bb2->index); } - if (bb->nexts) { - for (i = 0; i < bb->nexts->size; i++) { - bb2 = bb->nexts->data[i]; + } + if (bb->nexts) { + for (i = 0; i < bb->nexts->size; i++) { + bb2 = bb->nexts->data[i]; - printf("next : %p, index: %d\n", bb2, bb2->index); - } + printf("next : %p, index: %d\n", bb2, bb2->index); } + } #if 0 - if (bb->dominators_normal) { - for (i = 0; i < bb->dominators_normal->size; i++) - printf("dominator: %p\n", bb->dominators_normal->data[i]); - } + if (bb->dominators_normal) { + for (i = 0; i < bb->dominators_normal->size; i++) + printf("dominator: %p\n", bb->dominators_normal->data[i]); + } #endif - if (bb->dn_status_initeds) { - printf("inited: \n"); - for (i = 0; i < bb->dn_status_initeds->size; i++) { + if (bb->dn_status_initeds) { + printf("inited: \n"); + for (i = 0; i < bb->dn_status_initeds->size; i++) { + ds = bb->dn_status_initeds->data[i]; - scf_dn_status_t* ds = bb->dn_status_initeds->data[i]; - - scf_dn_status_print(ds); - } - printf("\n"); + scf_dn_status_print(ds); } + printf("\n"); + } #if 1 - if (bb->ds_malloced) { - scf_dn_status_t* ds; - - printf("auto gc: \n"); - for (i = 0; i < bb->ds_malloced->size; i++) { - ds = bb->ds_malloced->data[i]; + if (bb->ds_malloced) { + printf("auto gc: \n"); + for (i = 0; i < bb->ds_malloced->size; i++) { + ds = bb->ds_malloced->data[i]; - if (scf_vector_find_cmp(bb->ds_freed, ds, scf_dn_status_cmp_same_dn_indexes)) - continue; - scf_dn_status_print(ds); - } - printf("\n"); + if (scf_vector_find_cmp(bb->ds_freed, ds, scf_dn_status_cmp_same_dn_indexes)) + continue; + scf_dn_status_print(ds); } + printf("\n"); + } #endif - if (bb->entry_dn_actives) { - for (i = 0; i < bb->entry_dn_actives->size; i++) { - - scf_dag_node_t* dn = bb->entry_dn_actives->data[i]; - scf_variable_t* v = dn->var; + if (bb->entry_dn_actives) { + for (i = 0; i < bb->entry_dn_actives->size; i++) { + dn = bb->entry_dn_actives->data[i]; - if (v && v->w) - printf("entry active: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); - } + v = dn->var; + if (v && v->w) + printf("entry active: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); } + } - if (bb->exit_dn_actives) { - for (i = 0; i < bb->exit_dn_actives->size; i++) { - - scf_dag_node_t* dn = bb->exit_dn_actives->data[i]; - scf_variable_t* v = dn->var; + if (bb->exit_dn_actives) { + for (i = 0; i < bb->exit_dn_actives->size; i++) { + dn = bb->exit_dn_actives->data[i]; - if (v && v->w) - printf("exit active: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn); - } + v = dn->var; + if (v && v->w) + printf("exit active: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn); } + } - if (bb->entry_dn_aliases) { - for (i = 0; i < bb->entry_dn_aliases->size; i++) { - - scf_dag_node_t* dn = bb->entry_dn_aliases->data[i]; - scf_variable_t* v = dn->var; + if (bb->entry_dn_aliases) { + for (i = 0; i < bb->entry_dn_aliases->size; i++) { + dn = bb->entry_dn_aliases->data[i]; - if (v && v->w) - printf("entry alias: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); - } + v = dn->var; + if (v && v->w) + printf("entry alias: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); } - if (bb->exit_dn_aliases) { - for (i = 0; i < bb->exit_dn_aliases->size; i++) { - - scf_dag_node_t* dn = bb->exit_dn_aliases->data[i]; - scf_variable_t* v = dn->var; + } + if (bb->exit_dn_aliases) { + for (i = 0; i < bb->exit_dn_aliases->size; i++) { + dn = bb->exit_dn_aliases->data[i]; - if (v && v->w) - printf("exit alias: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn); - } + v = dn->var; + if (v && v->w) + printf("exit alias: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn); } + } - if (bb->dn_updateds) { - for (i = 0; i < bb->dn_updateds->size; i++) { - - scf_dag_node_t* dn = bb->dn_updateds->data[i]; - scf_variable_t* v = dn->var; + if (bb->dn_updateds) { + for (i = 0; i < bb->dn_updateds->size; i++) { + dn = bb->dn_updateds->data[i]; - if (v && v->w) - printf("updated: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); - } + v = dn->var; + if (v && v->w) + printf("updated: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); } + } - if (bb->dn_loads) { - for (i = 0; i < bb->dn_loads->size; i++) { - - scf_dag_node_t* dn = bb->dn_loads->data[i]; - scf_variable_t* v = dn->var; + if (bb->dn_loads) { + for (i = 0; i < bb->dn_loads->size; i++) { + dn = bb->dn_loads->data[i]; - if (v && v->w) - printf("loads: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); - } + v = dn->var; + if (v && v->w) + printf("loads: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); } + } - if (bb->dn_reloads) { - for (i = 0; i < bb->dn_reloads->size; i++) { - - scf_dag_node_t* dn = bb->dn_reloads->data[i]; - scf_variable_t* v = dn->var; + if (bb->dn_reloads) { + for (i = 0; i < bb->dn_reloads->size; i++) { + dn = bb->dn_reloads->data[i]; - if (v && v->w) - printf("reloads: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); - } + v = dn->var; + if (v && v->w) + printf("reloads: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); } + } - if (bb->dn_saves) { - for (i = 0; i < bb->dn_saves->size; i++) { - - scf_dag_node_t* dn = bb->dn_saves->data[i]; - scf_variable_t* v = dn->var; + if (bb->dn_saves) { + for (i = 0; i < bb->dn_saves->size; i++) { + dn = bb->dn_saves->data[i]; - if (v && v->w) - printf("saves: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn); - } + v = dn->var; + if (v && v->w) + printf("saves: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn); } + } - if (bb->dn_resaves) { - for (i = 0; i < bb->dn_resaves->size; i++) { - - scf_dag_node_t* dn = bb->dn_resaves->data[i]; - scf_variable_t* v = dn->var; + if (bb->dn_resaves) { + for (i = 0; i < bb->dn_resaves->size; i++) { + dn = bb->dn_resaves->data[i]; - if (v && v->w) - printf("resaves: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn); - } + v = dn->var; + if (v && v->w) + printf("resaves: v_%d_%d/%s, dn: %#lx\n", v->w->line, v->w->pos, v->w->text->data, 0xffff & (uintptr_t)dn); } - - printf("\n"); } + + printf("\n"); } } @@ -414,7 +405,6 @@ static int _copy_to_active_vars(scf_vector_t* active_vars, scf_vector_t* dag_nod { scf_dag_node_t* dn; scf_dn_status_t* ds; - int i; for (i = 0; i < dag_nodes->size; i++) { @@ -456,7 +446,6 @@ static int _copy_vars_by_active(scf_vector_t* dn_vec, scf_vector_t* ds_vars, int scf_dn_status_t* ds; scf_dag_node_t* dn; - int j; for (j = 0; j < ds_vars->size; j++) { @@ -487,7 +476,6 @@ static int _copy_updated_vars(scf_vector_t* dn_vec, scf_vector_t* ds_vars) scf_dn_status_t* ds; scf_dag_node_t* dn; - int j; for (j = 0; j < ds_vars->size; j++) { @@ -512,10 +500,11 @@ static int _copy_updated_vars(scf_vector_t* dn_vec, scf_vector_t* ds_vars) static int _bb_vars(scf_basic_block_t* bb) { - int ret = 0; - - scf_list_t* l; + scf_3ac_code_t* c; scf_dag_node_t* dn; + scf_list_t* l; + + int ret = 0; if (!bb->var_dag_nodes) { bb->var_dag_nodes = scf_vector_alloc(); @@ -524,18 +513,19 @@ static int _bb_vars(scf_basic_block_t* bb) } else scf_vector_clear(bb->var_dag_nodes, NULL); - for (l = scf_list_tail(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); - l = scf_list_prev(l)) { + for (l = scf_list_tail(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); l = scf_list_prev(l)) { - scf_3ac_code_t* c = scf_list_data(l, scf_3ac_code_t, list); + c = scf_list_data(l, scf_3ac_code_t, list); if (scf_type_is_jmp(c->op->type)) continue; - if (c->dsts) { - scf_3ac_operand_t* dst; - int j; + scf_3ac_operand_t* src; + scf_3ac_operand_t* dst; + scf_variable_t* v; + int j; + if (c->dsts) { for (j = 0; j < c->dsts->size; j++) { dst = c->dsts->data[j]; @@ -553,10 +543,6 @@ static int _bb_vars(scf_basic_block_t* bb) } if (c->srcs) { - scf_3ac_operand_t* src; - scf_variable_t* v; - int j; - for (j = 0; j < c->srcs->size; j++) { src = c->srcs->data[j]; @@ -584,12 +570,11 @@ static int _bb_vars(scf_basic_block_t* bb) int scf_basic_block_dag2(scf_basic_block_t* bb, scf_list_t* dag_list_head) { - scf_list_t* l; - - for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); - l = scf_list_next(l)) { + scf_list_t* l; + scf_3ac_code_t* c; - scf_3ac_code_t* c = scf_list_data(l, scf_3ac_code_t, list); + for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); l = scf_list_next(l)) { + c = scf_list_data(l, scf_3ac_code_t, list); int ret = scf_3ac_code_to_dag(c, dag_list_head); if (ret < 0) @@ -617,10 +602,8 @@ int scf_basic_block_dag(scf_basic_block_t* bb, scf_list_t* bb_list_head, scf_lis return ret; } - for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); - l = scf_list_next(l)) { - - c = scf_list_data(l, scf_3ac_code_t, list); + for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); l = scf_list_next(l)) { + c = scf_list_data(l, scf_3ac_code_t, list); if (c->active_vars) scf_vector_clear(c->active_vars, (void (*)(void*))scf_dn_status_free); @@ -643,7 +626,7 @@ static int _bb_init_pointer_aliases(scf_dn_status_t* ds_pointer, scf_dag_node_t* scf_dn_status_t* ds; scf_dn_status_t* ds2; scf_dn_status_t* ds3; - scf_vector_t* aliases; + scf_vector_t* aliases; int ret; int i; @@ -708,8 +691,8 @@ static int _bb_init_pointer_aliases(scf_dn_status_t* ds_pointer, scf_dag_node_t* static int _bb_init_var(scf_dag_node_t* dn, scf_3ac_code_t* c, scf_basic_block_t* bb, scf_list_t* bb_list_head) { - scf_dn_status_t* ds; - scf_dn_status_t* ds2; + scf_dn_status_t* ds; + scf_dn_status_t* ds2; scf_3ac_operand_t* src; if (!c->dn_status_initeds) { @@ -752,8 +735,8 @@ static int _bb_init_array_index(scf_3ac_code_t* c, scf_basic_block_t* bb, scf_li scf_dag_node_t* dn_index; scf_dag_node_t* dn_src; - scf_dn_status_t* ds; - scf_dn_status_t* ds2; + scf_dn_status_t* ds; + scf_dn_status_t* ds2; if (!c->dn_status_initeds) { c ->dn_status_initeds = scf_vector_alloc(); @@ -842,10 +825,9 @@ int scf_basic_block_inited_vars(scf_basic_block_t* bb, scf_list_t* bb_list_head) int ret = 0; - for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); - l = scf_list_next(l)) { + for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); l = scf_list_next(l)) { - c = scf_list_data(l, scf_3ac_code_t, list); + c = scf_list_data(l, scf_3ac_code_t, list); if (!c->active_vars) continue; @@ -954,18 +936,17 @@ int scf_basic_block_active_vars(scf_basic_block_t* bb) dn->updated = 0; } - for (l = scf_list_tail(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); - l = scf_list_prev(l)) { + for (l = scf_list_tail(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); l = scf_list_prev(l)) { - c = scf_list_data(l, scf_3ac_code_t, list); + c = scf_list_data(l, scf_3ac_code_t, list); - if (scf_type_is_jmp(c->op->type) - || SCF_OP_3AC_END == c->op->type) + if (scf_type_is_jmp(c->op->type) || SCF_OP_3AC_END == c->op->type) continue; - if (c->dsts) { - scf_3ac_operand_t* dst; + scf_3ac_operand_t* src; + scf_3ac_operand_t* dst; + if (c->dsts) { for (j = 0; j < c->dsts->size; j++) { dst = c->dsts->data[j]; @@ -982,8 +963,6 @@ int scf_basic_block_active_vars(scf_basic_block_t* bb) } if (c->srcs) { - scf_3ac_operand_t* src; - for (j = 0; j < c->srcs->size; j++) { src = c->srcs->data[j]; @@ -1153,11 +1132,15 @@ int scf_basic_block_search_bfs(scf_basic_block_t* root, scf_basic_block_bfs_pt f if (!root) return -EINVAL; - scf_vector_t* queue = scf_vector_alloc(); + scf_basic_block_t* bb; + scf_vector_t* queue; + scf_vector_t* checked; + + queue = scf_vector_alloc(); if (!queue) return -ENOMEM; - scf_vector_t* checked = scf_vector_alloc(); + checked = scf_vector_alloc(); if (!queue) { scf_vector_free(queue); return -ENOMEM; @@ -1171,11 +1154,11 @@ int scf_basic_block_search_bfs(scf_basic_block_t* root, scf_basic_block_bfs_pt f int i = 0; while (i < queue->size) { - scf_basic_block_t* bb = queue->data[i]; + bb = queue->data[i]; int j; for (j = 0; j < checked->size; j++) { - if (bb == checked->data[j]) + if (bb == checked->data[j]) goto next; } @@ -1195,8 +1178,6 @@ next: failed: scf_vector_free(queue); scf_vector_free(checked); - queue = NULL; - checked = NULL; return ret; } @@ -1213,8 +1194,7 @@ int scf_basic_block_search_dfs_prev(scf_basic_block_t* root, scf_basic_block_dfs root->visited_flag = 1; for (i = 0; i < root->prevs->size; ++i) { - - bb = root->prevs->data[i]; + bb = root->prevs->data[i]; if (bb->visited_flag) continue; @@ -1249,8 +1229,7 @@ int scf_basic_block_loads_saves(scf_basic_block_t* bb, scf_list_t* bb_list_head) int i; for (i = 0; i < bb->entry_dn_actives->size; i++) { - - dn = bb->entry_dn_actives->data[i]; + dn = bb->entry_dn_actives->data[i]; if (dn->var->extra_flag) continue; @@ -1265,10 +1244,10 @@ int scf_basic_block_loads_saves(scf_basic_block_t* bb, scf_list_t* bb_list_head) } for (i = 0; i < bb->exit_dn_actives->size; i++) { - - dn = bb->exit_dn_actives->data[i]; + dn = bb->exit_dn_actives->data[i]; if (!scf_vector_find(bb->dn_updateds, dn)) { + if (l != scf_list_head(bb_list_head) || !dn->var->arg_flag) continue; } @@ -1284,10 +1263,10 @@ int scf_basic_block_loads_saves(scf_basic_block_t* bb, scf_list_t* bb_list_head) } for (i = 0; i < bb->exit_dn_aliases->size; i++) { - - dn = bb->exit_dn_aliases->data[i]; + dn = bb->exit_dn_aliases->data[i]; if (!scf_vector_find(bb->dn_updateds, dn)) { + if (l != scf_list_head(bb_list_head) || !dn->var->arg_flag) continue; } @@ -1299,4 +1278,3 @@ int scf_basic_block_loads_saves(scf_basic_block_t* bb, scf_list_t* bb_list_head) return 0; } - diff --git a/core/scf_basic_block.h b/core/scf_basic_block.h index 852adb3..0a6b6ab 100644 --- a/core/scf_basic_block.h +++ b/core/scf_basic_block.h @@ -48,10 +48,8 @@ struct scf_basic_block_s scf_vector_t* prevs; // prev basic blocks scf_vector_t* nexts; // next basic blocks - scf_vector_t* dominators_normal; - scf_vector_t* dominators_reverse; - int dfo_normal; - int dfo_reverse; + scf_vector_t* dominators; + int dfo; scf_vector_t* entry_dn_delivery; scf_vector_t* entry_dn_inactives; @@ -109,7 +107,7 @@ struct scf_basic_block_s typedef int (*scf_basic_block_bfs_pt)(scf_basic_block_t* bb, void* data, scf_vector_t* queue); typedef int (*scf_basic_block_dfs_pt)(scf_basic_block_t* bb, void* data); -int scf_basic_block_search_bfs(scf_basic_block_t* root, scf_basic_block_bfs_pt find, void* data); +int scf_basic_block_search_bfs (scf_basic_block_t* root, scf_basic_block_bfs_pt find, void* data); int scf_basic_block_search_dfs_prev(scf_basic_block_t* root, scf_basic_block_dfs_pt find, void* data, scf_vector_t* results); @@ -139,4 +137,3 @@ void scf_basic_block_mov_code(scf_list_t* start, scf_basic_block_ int scf_basic_block_inited_by3ac(scf_basic_block_t* bb); #endif - diff --git a/core/scf_function.h b/core/scf_function.h index 518cc67..bccf075 100644 --- a/core/scf_function.h +++ b/core/scf_function.h @@ -35,7 +35,6 @@ struct scf_function_s { scf_vector_t* bb_loops; scf_vector_t* bb_groups; int max_dfo; - int max_dfo_reverse; scf_vector_t* text_relas; // re-localtions in .text segment scf_vector_t* data_relas; // re-localtions in .data segment @@ -73,4 +72,3 @@ int scf_function_like_argv(scf_vector_t* argv0, scf_vector_t* argv1) int scf_function_signature(scf_function_t* f); #endif - diff --git a/core/scf_optimizer.c b/core/scf_optimizer.c index 7767467..ad0dbfd 100644 --- a/core/scf_optimizer.c +++ b/core/scf_optimizer.c @@ -11,8 +11,7 @@ extern scf_optimizer_t scf_optimizer_active_vars; extern scf_optimizer_t scf_optimizer_pointer_aliases; extern scf_optimizer_t scf_optimizer_loads_saves; -extern scf_optimizer_t scf_optimizer_dominators_normal; -extern scf_optimizer_t scf_optimizer_dominators_reverse; +extern scf_optimizer_t scf_optimizer_dominators; extern scf_optimizer_t scf_optimizer_auto_gc_find; extern scf_optimizer_t scf_optimizer_auto_gc; @@ -23,12 +22,11 @@ extern scf_optimizer_t scf_optimizer_const_teq; extern scf_optimizer_t scf_optimizer_loop; extern scf_optimizer_t scf_optimizer_group; - extern scf_optimizer_t scf_optimizer_generate_loads_saves; static scf_optimizer_t* scf_optimizers[] = { - &scf_optimizer_inline, // global optimizer + &scf_optimizer_inline, // global optimizer &scf_optimizer_dag, @@ -39,16 +37,16 @@ static scf_optimizer_t* scf_optimizers[] = &scf_optimizer_pointer_aliases, &scf_optimizer_loads_saves, - &scf_optimizer_auto_gc_find, // global optimizer + &scf_optimizer_auto_gc_find, // global optimizer - &scf_optimizer_dominators_normal, + &scf_optimizer_dominators, &scf_optimizer_auto_gc, &scf_optimizer_basic_block, &scf_optimizer_const_teq, - &scf_optimizer_dominators_normal, + &scf_optimizer_dominators, &scf_optimizer_loop, &scf_optimizer_group, @@ -93,12 +91,15 @@ static void __scf_loops_print(scf_bb_group_t* loop) if (loop->loop_childs) { printf("childs: %d\n", loop->loop_childs->size); + for (k = 0; k < loop->loop_childs->size; k++) printf("%p ", loop->loop_childs->data[k]); printf("\n"); } + if (loop->loop_parent) printf("parent: %p\n", loop->loop_parent); + printf("loop_layers: %d\n\n", loop->loop_layers); } @@ -127,7 +128,6 @@ int scf_optimize(scf_ast_t* ast, scf_vector_t* functions) int j; for (i = 0; i < n; i++) { - opt = scf_optimizers[i]; if (SCF_OPTIMIZER_GLOBAL == opt->flags) { @@ -156,8 +156,7 @@ int scf_optimize(scf_ast_t* ast, scf_vector_t* functions) #if 1 for (i = 0; i < functions->size; i++) { - - scf_function_t* f = functions->data[i]; + f = functions->data[i]; if (!f->node.define_flag) continue; @@ -165,10 +164,10 @@ int scf_optimize(scf_ast_t* ast, scf_vector_t* functions) scf_logi("------- %s() ------\n", f->node.w->text->data); scf_basic_block_print_list(&f->basic_block_list_head); - scf_loops_print(f->bb_loops); + + scf_loops_print (f->bb_loops); scf_groups_print(f->bb_groups); } #endif return 0; } - diff --git a/core/scf_optimizer_auto_gc.c b/core/scf_optimizer_auto_gc.c index ef20342..9192bbe 100644 --- a/core/scf_optimizer_auto_gc.c +++ b/core/scf_optimizer_auto_gc.c @@ -1144,6 +1144,9 @@ static int _auto_gc_last_free(scf_ast_t* ast, scf_function_t* f) scf_list_t* bb_list_head = &f->basic_block_list_head; scf_list_t* l; scf_basic_block_t* bb; + scf_dn_status_t* ds; + scf_dag_node_t* dn; + scf_variable_t* v; scf_vector_t* local_arrays; l = scf_list_tail(bb_list_head); @@ -1158,10 +1161,10 @@ static int _auto_gc_last_free(scf_ast_t* ast, scf_function_t* f) int ret; int i; for (i = 0; i < bb->ds_malloced->size; ) { + ds = bb->ds_malloced->data[i]; - scf_dn_status_t* ds = bb->ds_malloced->data[i]; - scf_dag_node_t* dn = ds->dag_node; - scf_variable_t* v = dn->var; + dn = ds->dag_node; + v = dn->var; scf_loge("f: %s, last free: v_%d_%d/%s, ds->ret: %u\n", f->node.w->text->data, v->w->line, v->w->pos, v->w->text->data, ds->ret); @@ -1232,8 +1235,8 @@ static int _auto_gc_last_free(scf_ast_t* ast, scf_function_t* f) for (j = 0; j < vec->size; j++) { \ bb1 = vec->data[j]; \ \ - if (bb1->dfo_normal > dfo) \ - dfo = bb1->dfo_normal; \ + if (bb1->dfo > dfo) \ + dfo = bb1->dfo; \ } \ } while (0) AUTO_GC_FIND_MAX_DFO(); @@ -1247,10 +1250,10 @@ static int _auto_gc_last_free(scf_ast_t* ast, scf_function_t* f) } AUTO_GC_FIND_MAX_DFO(); - for (j = 0; j < bb->dominators_normal->size; j++) { - bb_dominator = bb->dominators_normal->data[j]; + for (j = 0; j < bb->dominators->size; j++) { + bb_dominator = bb->dominators->data[j]; - if (bb_dominator->dfo_normal > dfo) + if (bb_dominator->dfo > dfo) break; } @@ -1268,9 +1271,6 @@ static int _auto_gc_last_free(scf_ast_t* ast, scf_function_t* f) i++; } - scf_dag_node_t* dn; - scf_variable_t* v; - for (i = 0; i < local_arrays->size; i++) { dn = local_arrays->data[i]; diff --git a/core/scf_optimizer_dominators.c b/core/scf_optimizer_dominators.c index 97dd406..9c2d52b 100644 --- a/core/scf_optimizer_dominators.c +++ b/core/scf_optimizer_dominators.c @@ -36,7 +36,7 @@ static int __bb_dfs_tree(scf_basic_block_t* root, scf_vector_t* edges, int* tota return ret; } - root->dfo_normal = --*total; + root->dfo = --*total; return 0; } @@ -75,9 +75,9 @@ static int _bb_cmp_dfo(const void* p0, const void* p1) scf_basic_block_t* bb0 = *(scf_basic_block_t**)p0; scf_basic_block_t* bb1 = *(scf_basic_block_t**)p1; - if (bb0->dfo_normal < bb1->dfo_normal) + if (bb0->dfo < bb1->dfo) return -1; - if (bb0->dfo_normal > bb1->dfo_normal) + if (bb0->dfo > bb1->dfo) return 1; return 0; } @@ -92,7 +92,7 @@ static int _bb_intersection(scf_vector_t* dst, scf_vector_t* src) scf_basic_block_t* bb0 = dst->data[k0]; scf_basic_block_t* bb1 = src->data[k1]; - if (bb0->dfo_normal < bb1->dfo_normal) { + if (bb0->dfo < bb1->dfo) { int ret = scf_vector_del(dst, bb0); if (ret < 0) @@ -100,7 +100,7 @@ static int _bb_intersection(scf_vector_t* dst, scf_vector_t* src) continue; } - if (bb0->dfo_normal > bb1->dfo_normal) { + if (bb0->dfo > bb1->dfo) { ++k1; continue; } @@ -114,7 +114,7 @@ static int _bb_intersection(scf_vector_t* dst, scf_vector_t* src) return 0; } -static int _bb_find_dominators_normal(scf_list_t* bb_list_head) +static int _bb_find_dominators(scf_list_t* bb_list_head) { if (!bb_list_head) return -EINVAL; @@ -156,35 +156,35 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) scf_vector_qsort(bb->prevs, _bb_cmp_dfo); scf_vector_qsort(bb->nexts, _bb_cmp_dfo); - if (0 == bb->dfo_normal) { + if (0 == bb->dfo) { - if (!bb->dominators_normal) { - bb->dominators_normal = scf_vector_alloc(); - if (!bb->dominators_normal) { + if (!bb->dominators) { + bb->dominators = scf_vector_alloc(); + if (!bb->dominators) { ret = -ENOMEM; goto error; } } else - scf_vector_clear(bb->dominators_normal, NULL); + scf_vector_clear(bb->dominators, NULL); - ret = scf_vector_add(bb->dominators_normal, bb); + ret = scf_vector_add(bb->dominators, bb); if (ret < 0) goto error; - scf_logd("bb: %p_%d, dom size: %d\n", bb, bb->dfo_normal, bb->dominators_normal->size); + scf_logd("bb: %p_%d, dom size: %d\n", bb, bb->dfo, bb->dominators->size); continue; } - if (bb->dominators_normal) - scf_vector_free(bb->dominators_normal); + if (bb->dominators) + scf_vector_free(bb->dominators); - bb->dominators_normal = scf_vector_clone(all); - if (!bb->dominators_normal) { + bb->dominators = scf_vector_clone(all); + if (!bb->dominators) { ret = -ENOMEM; goto error; } - scf_logd("bb: %p_%d, dom size: %d\n", bb, bb->dfo_normal, bb->dominators_normal->size); + scf_logd("bb: %p_%d, dom size: %d\n", bb, bb->dfo, bb->dominators->size); } do { @@ -193,25 +193,25 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) for (i = 1; i < all->size; i++) { bb = all->data[i]; - scf_vector_t* dominators_normal = NULL; + scf_vector_t* dominators = NULL; for (j = 0; j < bb->prevs->size; j++) { prev = bb->prevs->data[j]; - scf_logd("bb: %p_%d, prev: %p_%d\n", bb, bb->dfo_normal, prev, prev->dfo_normal); + scf_logd("bb: %p_%d, prev: %p_%d\n", bb, bb->dfo, prev, prev->dfo); - if (!dominators_normal) { - dominators_normal = scf_vector_clone(prev->dominators_normal); - if (!dominators_normal) { + if (!dominators) { + dominators = scf_vector_clone(prev->dominators); + if (!dominators) { ret = -ENOMEM; goto error; } continue; } - ret = _bb_intersection(dominators_normal, prev->dominators_normal); + ret = _bb_intersection(dominators, prev->dominators); if (ret < 0) { - scf_vector_free(dominators_normal); + scf_vector_free(dominators); goto error; } } @@ -219,46 +219,46 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) scf_basic_block_t* dom = NULL; scf_basic_block_t* dom1 = bb; - for (j = 0; j < dominators_normal->size; j++) { - dom = dominators_normal->data[j]; + for (j = 0; j < dominators->size; j++) { + dom = dominators->data[j]; - if (bb->dfo_normal == dom->dfo_normal) + if (bb->dfo == dom->dfo) break; - if (bb->dfo_normal < dom->dfo_normal) + if (bb->dfo < dom->dfo) break; } - if (bb->dfo_normal < dom->dfo_normal) { + if (bb->dfo < dom->dfo) { - for (; j < dominators_normal->size; j++) { - dom = dominators_normal->data[j]; - dominators_normal->data[j] = dom1; + for (; j < dominators->size; j++) { + dom = dominators->data[j]; + dominators->data[j] = dom1; dom1 = dom; } } - if (j == dominators_normal->size) { - ret = scf_vector_add(dominators_normal, dom1); + if (j == dominators->size) { + ret = scf_vector_add(dominators, dom1); if (ret < 0) { - scf_vector_free(dominators_normal); + scf_vector_free(dominators); goto error; } } - if (dominators_normal->size != bb->dominators_normal->size) + if (dominators->size != bb->dominators->size) ++changed; else { int k0 = 0; int k1 = 0; - while (k0 < dominators_normal->size && k1 < bb->dominators_normal->size) { + while (k0 < dominators->size && k1 < bb->dominators->size) { - scf_basic_block_t* dom0 = dominators_normal->data[k0]; - scf_basic_block_t* dom1 = bb->dominators_normal->data[k1]; + scf_basic_block_t* dom0 = dominators->data[k0]; + scf_basic_block_t* dom1 = bb->dominators->data[k1]; - if (dom0->dfo_normal < dom1->dfo_normal) { + if (dom0->dfo < dom1->dfo) { ++changed; break; - } else if (dom0->dfo_normal > dom1->dfo_normal) { + } else if (dom0->dfo > dom1->dfo) { ++changed; break; } else { @@ -268,9 +268,9 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) } } - scf_vector_free(bb->dominators_normal); - bb->dominators_normal = dominators_normal; - dominators_normal = NULL; + scf_vector_free(bb->dominators); + bb->dominators = dominators; + dominators = NULL; } } while (changed > 0); #if 0 @@ -278,10 +278,10 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) bb = all->data[i]; int j; - for (j = 0; j < bb->dominators_normal->size; j++) { + for (j = 0; j < bb->dominators->size; j++) { - scf_basic_block_t* dom = bb->dominators_normal->data[j]; - scf_logw("bb: %p_%d, dom: %p_%d\n", bb, bb->dfo_normal, dom, dom->dfo_normal); + scf_basic_block_t* dom = bb->dominators->data[j]; + scf_logw("bb: %p_%d, dom: %p_%d\n", bb, bb->dfo, dom, dom->dfo); } printf("\n"); } @@ -293,13 +293,14 @@ error: return ret; } -static int _optimize_dominators_normal(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions) +static int _optimize_dominators(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions) { if (!f) return -EINVAL; scf_list_t* bb_list_head = &f->basic_block_list_head; scf_list_t* l; + scf_bb_edge_t* edge; scf_basic_block_t* bb; int ret; @@ -315,14 +316,14 @@ static int _optimize_dominators_normal(scf_ast_t* ast, scf_function_t* f, scf_ve return ret; for (i = 0; i < f->dfs_tree->size; i++) { - scf_bb_edge_t* edge = f->dfs_tree->data[i]; + edge = f->dfs_tree->data[i]; scf_logd("bb_%p_%d --> bb_%p_%d\n", - edge->start, edge->start->dfo_normal, - edge->end, edge->end->dfo_normal); + edge->start, edge->start->dfo, + edge->end, edge->end->dfo); } - ret = _bb_find_dominators_normal(bb_list_head); + ret = _bb_find_dominators(bb_list_head); if (ret < 0) { scf_loge("\n"); return ret; @@ -332,12 +333,11 @@ static int _optimize_dominators_normal(scf_ast_t* ast, scf_function_t* f, scf_ve return 0; } -scf_optimizer_t scf_optimizer_dominators_normal = +scf_optimizer_t scf_optimizer_dominators = { - .name = "dominators_normal", + .name = "dominators", - .optimize = _optimize_dominators_normal, + .optimize = _optimize_dominators, .flags = SCF_OPTIMIZER_LOCAL, }; - diff --git a/core/scf_optimizer_dominators_reverse.c b/core/scf_optimizer_dominators_reverse.c deleted file mode 100644 index 560f4d0..0000000 --- a/core/scf_optimizer_dominators_reverse.c +++ /dev/null @@ -1,348 +0,0 @@ -#include"scf_optimizer.h" - -static int __bb_dfs_tree(scf_basic_block_t* root, scf_vector_t* edges, int* total) -{ - scf_basic_block_t* bb; - scf_bb_edge_t* edge; - - int i; - int ret; - - assert(!root->jmp_flag); - - root->visited_flag = 1; - - for (i = 0; i < root->prevs->size; ++i) { - - bb = root->prevs->data[i]; - - if (bb->visited_flag) - continue; - - edge = malloc(sizeof(scf_bb_edge_t)); - if (!edge) - return -ENOMEM; - - edge->start = root; - edge->end = bb; - - ret = scf_vector_add(edges, edge); - if ( ret < 0) - return ret; - - ret = __bb_dfs_tree(bb, edges, total); - if ( ret < 0) - return ret; - } - - root->dfo_reverse = --*total; - return 0; -} - -static int _bb_dfs_tree(scf_list_t* bb_list_head, scf_function_t* f) -{ - if (!bb_list_head) - return -EINVAL; - - if (scf_list_empty(bb_list_head)) - return 0; - - scf_list_t* l; - scf_basic_block_t* bb; - - int total = 0; - - for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); - l = scf_list_next(l)) { - - bb = scf_list_data(l, scf_basic_block_t, list); - - bb->visited_flag = 0; - - if (!bb->jmp_flag) - ++total; - } - assert(&bb->list == scf_list_tail(bb_list_head)); - - f->max_dfo_reverse = total - 1; - - return __bb_dfs_tree(bb, f->dfs_tree, &total); -} - -static int _bb_cmp_dfo(const void* p0, const void* p1) -{ - scf_basic_block_t* bb0 = *(scf_basic_block_t**)p0; - scf_basic_block_t* bb1 = *(scf_basic_block_t**)p1; - - if (bb0->dfo_reverse < bb1->dfo_reverse) - return -1; - if (bb0->dfo_reverse > bb1->dfo_reverse) - return 1; - return 0; -} - -static int _bb_intersection(scf_vector_t* dst, scf_vector_t* src) -{ - int k0 = 0; - int k1 = 0; - - while (k0 < dst->size && k1 < src->size) { - - scf_basic_block_t* bb0 = dst->data[k0]; - scf_basic_block_t* bb1 = src->data[k1]; - - if (bb0->dfo_reverse < bb1->dfo_reverse) { - - int ret = scf_vector_del(dst, bb0); - if (ret < 0) - return ret; - continue; - } - - if (bb0->dfo_reverse > bb1->dfo_reverse) { - ++k1; - continue; - } - - ++k0; - ++k1; - } - - dst->size = k0; - - return 0; -} - -static int _bb_find_dominators_reverse(scf_list_t* bb_list_head) -{ - if (!bb_list_head) - return -EINVAL; - - if (scf_list_empty(bb_list_head)) - return 0; - - scf_list_t* l; - scf_basic_block_t* bb; - scf_vector_t* all; - - int i; - int j; - int ret; - int changed; - - all = scf_vector_alloc(); - if (!all) - return -ENOMEM; - - for (l = scf_list_tail(bb_list_head); l != scf_list_sentinel(bb_list_head); - l = scf_list_prev(l)) { - - bb = scf_list_data(l, scf_basic_block_t, list); - if (bb->jmp_flag) - continue; - - ret = scf_vector_add(all, bb); - if (ret < 0) - goto error; - } - - scf_vector_qsort(all, _bb_cmp_dfo); - - for (i = 0; i < all->size; i++) { - bb = all->data[i]; - - scf_vector_qsort(bb->prevs, _bb_cmp_dfo); - scf_vector_qsort(bb->nexts, _bb_cmp_dfo); - - if (0 == bb->dfo_reverse) { - - if (!bb->dominators_reverse) { - bb->dominators_reverse = scf_vector_alloc(); - if (!bb->dominators_reverse) { - ret = -ENOMEM; - goto error; - } - } else - scf_vector_clear(bb->dominators_reverse, NULL); - - ret = scf_vector_add(bb->dominators_reverse, bb); - if (ret < 0) - goto error; - - scf_logd("bb: %p_%d, dom size: %d\n", bb, bb->dfo_reverse, bb->dominators_reverse->size); - continue; - } - - if (bb->dominators_reverse) - scf_vector_free(bb->dominators_reverse); - - bb->dominators_reverse = scf_vector_clone(all); - if (!bb->dominators_reverse) { - ret = -ENOMEM; - goto error; - } - - scf_logd("bb: %p_%d, dom size: %d\n", bb, bb->dfo_reverse, bb->dominators_reverse->size); - } - - do { - changed = 0; - - for (i = 1; i < all->size; i++) { - bb = all->data[i]; - - scf_vector_t* dominators_reverse = NULL; - - for (j = 0; j < bb->nexts->size; j++) { - scf_basic_block_t* next = bb->nexts->data[j]; - scf_logd("bb: %p_%d, next: %p_%d\n", bb, bb->dfo_normal, next, next->dfo_normal); - - if (!dominators_reverse) { - dominators_reverse = scf_vector_clone(next->dominators_reverse); - if (!dominators_reverse) { - ret = -ENOMEM; - goto error; - } - continue; - } - - ret = _bb_intersection(dominators_reverse, next->dominators_reverse); - if (ret < 0) { - scf_vector_free(dominators_reverse); - goto error; - } - } - - scf_logd("bb: %p, dominators_reverse: %p, bb->nexts->size: %d\n", - bb, dominators_reverse, bb->nexts->size); - - scf_basic_block_t* dom = NULL; - scf_basic_block_t* dom1 = bb; - - for (j = 0; j < dominators_reverse->size; j++) { - dom = dominators_reverse->data[j]; - - if (bb->dfo_reverse == dom->dfo_reverse) - break; - - if (bb->dfo_reverse < dom->dfo_reverse) - break; - } - if (bb->dfo_reverse < dom->dfo_reverse) { - - for (; j < dominators_reverse->size; j++) { - dom = dominators_reverse->data[j]; - dominators_reverse->data[j] = dom1; - dom1 = dom; - } - } - if (j == dominators_reverse->size) { - ret = scf_vector_add(dominators_reverse, dom1); - if (ret < 0) { - scf_vector_free(dominators_reverse); - goto error; - } - } - - if (dominators_reverse->size != bb->dominators_reverse->size) { - scf_vector_free(bb->dominators_reverse); - bb->dominators_reverse = dominators_reverse; - dominators_reverse = NULL; - ++changed; - } else { - int k0 = 0; - int k1 = 0; - - while (k0 < dominators_reverse->size && k1 < bb->dominators_reverse->size) { - - scf_basic_block_t* dom0 = dominators_reverse->data[k0]; - scf_basic_block_t* dom1 = bb->dominators_reverse->data[k1]; - - if (dom0->dfo_reverse < dom1->dfo_reverse) - ++k0; - else if (dom0->dfo_reverse > dom1->dfo_reverse) - ++k1; - else { - ++k0; - ++k1; - } - } - - if (k0 == k1) { - scf_vector_free(dominators_reverse); - dominators_reverse = NULL; - } else { - scf_vector_free(bb->dominators_reverse); - bb->dominators_reverse = dominators_reverse; - dominators_reverse = NULL; - ++changed; - } - } - } - } while (changed > 0); -#if 0 - for (i = 0; i < all->size; i++) { - bb = all->data[i]; - - int j; - for (j = 0; j < bb->dominators_reverse->size; j++) { - - scf_basic_block_t* dom = bb->dominators_reverse->data[j]; - scf_logd("bb: %p_%d, dom: %p_%d\n", bb, bb->dfo_reverse, dom, dom->dfo_reverse); - } - printf("\n"); - } -#endif - - ret = 0; -error: - scf_vector_free(all); - return ret; -} - -static int _optimize_dominators_reverse(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions) -{ - if (!f) - return -EINVAL; - - scf_list_t* bb_list_head = &f->basic_block_list_head; - scf_list_t* l; - scf_basic_block_t* bb; - - int ret; - int i; - - if (scf_list_empty(bb_list_head)) - return 0; - - scf_vector_clear(f->dfs_tree, free); - - ret = _bb_dfs_tree(bb_list_head, f); - if (ret < 0) - return ret; - - for (i = 0; i < f->dfs_tree->size; i++) { - scf_bb_edge_t* edge = f->dfs_tree->data[i]; - - scf_logd("bb_%p_%d --> bb_%p_%d\n", - edge->start, edge->start->dfo_reverse, - edge->end, edge->end->dfo_reverse); - } - - ret = _bb_find_dominators_reverse(bb_list_head); - if (ret < 0) { - scf_loge("\n"); - return ret; - } - -// scf_basic_block_print_list(bb_list_head); - return 0; -} - -scf_optimizer_t scf_optimizer_dominators_reverse = -{ - .name = "dominators_reverse", - - .optimize = _optimize_dominators_reverse, -}; - diff --git a/core/scf_optimizer_loop.c b/core/scf_optimizer_loop.c index 8481a03..60e2daa 100644 --- a/core/scf_optimizer_loop.c +++ b/core/scf_optimizer_loop.c @@ -3,7 +3,6 @@ static int __bb_dfs_loop2(scf_basic_block_t* root, scf_vector_t* loop) { scf_basic_block_t* bb; - int i; assert(!root->jmp_flag); @@ -11,8 +10,7 @@ static int __bb_dfs_loop2(scf_basic_block_t* root, scf_vector_t* loop) root->visited_flag = 1; for (i = 0; i < root->prevs->size; ++i) { - - bb = root->prevs->data[i]; + bb = root->prevs->data[i]; if (bb->visited_flag) continue; @@ -45,9 +43,7 @@ static int __bb_dfs_loop(scf_list_t* bb_list_head, scf_basic_block_t* bb, scf_ba if (ret < 0) return ret; - for (l = scf_list_tail(bb_list_head); l != scf_list_sentinel(bb_list_head); - l = scf_list_prev(l)) { - + for (l = scf_list_tail(bb_list_head); l != scf_list_sentinel(bb_list_head); l = scf_list_prev(l)) { bb2 = scf_list_data(l, scf_basic_block_t, list); if (bb2->jmp_flag) @@ -118,8 +114,7 @@ static int _bb_dfs_loop(scf_list_t* bb_list_head, scf_vector_t* loops) int nblocks = 0; - for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); - l = scf_list_next(l)) { + for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); l = scf_list_next(l)) { bb = scf_list_data(l, scf_basic_block_t, list); @@ -132,17 +127,17 @@ static int _bb_dfs_loop(scf_list_t* bb_list_head, scf_vector_t* loops) int i = 0; int j = 0; - while (i < bb->nexts->size && j < bb->dominators_normal->size) { + while (i < bb->nexts->size && j < bb->dominators->size) { scf_basic_block_t* next = bb->nexts->data[i]; - scf_basic_block_t* dom = bb->dominators_normal->data[j]; + scf_basic_block_t* dom = bb->dominators->data[j]; - if (next->dfo_normal < dom->dfo_normal) { + if (next->dfo < dom->dfo) { ++i; continue; } - if (next->dfo_normal > dom->dfo_normal) { + if (next->dfo > dom->dfo) { ++j; continue; } @@ -153,7 +148,6 @@ static int _bb_dfs_loop(scf_list_t* bb_list_head, scf_vector_t* loops) ret = __bb_dfs_loop(bb_list_head, bb, dom, loop); if (ret < 0) { - scf_loge("\n"); scf_vector_free(loop); return ret; } @@ -317,16 +311,13 @@ static int __bb_loop_merge(scf_vector_t* loops) static int _bb_loop_merge(scf_vector_t* loops) { scf_bb_group_t* loop; - - int ret; int i; for (i = 0; i < loops->size; i++) { loop = loops->data[i]; if (loop->loop_childs) { - - ret = _bb_loop_merge(loop->loop_childs); + int ret = _bb_loop_merge(loop->loop_childs); if (ret < 0) return ret; } @@ -338,8 +329,6 @@ static int _bb_loop_merge(scf_vector_t* loops) static void _bb_loop_sort(scf_vector_t* loops) { scf_bb_group_t* loop; - - int ret; int i; for (i = 0; i < loops->size; i++) { @@ -623,7 +612,7 @@ static int _bb_loop_add_pre_post(scf_function_t* f) } assert(n < exit->prevs->size); - bb ->nexts->data[k] = post; + bb->nexts->data[k] = post; if (!scf_vector_find(exit->prevs, post)) exit->prevs->data[n] = post; @@ -862,4 +851,3 @@ scf_optimizer_t scf_optimizer_loop = .flags = SCF_OPTIMIZER_LOCAL, }; - diff --git a/parse/Makefile b/parse/Makefile index d793978..e3ca067 100644 --- a/parse/Makefile +++ b/parse/Makefile @@ -110,7 +110,6 @@ CFILES += ../core/scf_optimizer_loads_saves.c CFILES += ../core/scf_optimizer_auto_gc_find.c CFILES += ../core/scf_optimizer_auto_gc.c CFILES += ../core/scf_optimizer_dominators.c -CFILES += ../core/scf_optimizer_dominators_reverse.c CFILES += ../core/scf_optimizer_basic_block.c CFILES += ../core/scf_optimizer_const_teq.c CFILES += ../core/scf_optimizer_loop.c