From 9a6c7bb084387ff8fb057208175e18cccdefd803 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Thu, 7 Dec 2023 14:40:07 +0800 Subject: [PATCH] delete some unused code --- core/scf_optimizer_dominators.c | 46 +++++++++++++++------------------ core/scf_variable.c | 27 ------------------- core/scf_variable.h | 4 --- 3 files changed, 21 insertions(+), 56 deletions(-) diff --git a/core/scf_optimizer_dominators.c b/core/scf_optimizer_dominators.c index 3020b2f..e5f310a 100644 --- a/core/scf_optimizer_dominators.c +++ b/core/scf_optimizer_dominators.c @@ -13,8 +13,7 @@ static int __bb_dfs_tree(scf_basic_block_t* root, scf_vector_t* edges, int* tota root->visited_flag = 1; for (i = 0; i < root->nexts->size; ++i) { - - bb = root->nexts->data[i]; + bb = root->nexts->data[i]; if (bb->visited_flag) continue; @@ -27,8 +26,10 @@ static int __bb_dfs_tree(scf_basic_block_t* root, scf_vector_t* edges, int* tota edge->end = bb; ret = scf_vector_add(edges, edge); - if ( ret < 0) + if (ret < 0) { + free(edge); return ret; + } ret = __bb_dfs_tree(bb, edges, total); if ( ret < 0) @@ -123,6 +124,7 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) scf_list_t* l; scf_basic_block_t* bb; + scf_basic_block_t* prev; scf_vector_t* all; int i; @@ -189,12 +191,13 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) changed = 0; for (i = 1; i < all->size; i++) { - bb = all->data[i]; + bb = all->data[i]; scf_vector_t* dominators_normal = NULL; for (j = 0; j < bb->prevs->size; j++) { - scf_basic_block_t* prev = bb->prevs->data[j]; + prev = bb->prevs->data[j]; + scf_logd("bb: %p_%d, prev: %p_%d\n", bb, bb->dfo_normal, prev, prev->dfo_normal); if (!dominators_normal) { @@ -241,12 +244,9 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) } } - if (dominators_normal->size != bb->dominators_normal->size) { - scf_vector_free(bb->dominators_normal); - bb->dominators_normal = dominators_normal; - dominators_normal = NULL; + if (dominators_normal->size != bb->dominators_normal->size) ++changed; - } else { + else { int k0 = 0; int k1 = 0; @@ -255,26 +255,22 @@ static int _bb_find_dominators_normal(scf_list_t* bb_list_head) scf_basic_block_t* dom0 = dominators_normal->data[k0]; scf_basic_block_t* dom1 = bb->dominators_normal->data[k1]; - if (dom0->dfo_normal < dom1->dfo_normal) - ++k0; - else if (dom0->dfo_normal > dom1->dfo_normal) - ++k1; - else { + if (dom0->dfo_normal < dom1->dfo_normal) { + ++changed; + break; + } else if (dom0->dfo_normal > dom1->dfo_normal) { + ++changed; + break; + } else { ++k0; ++k1; } } - - if (k0 == k1) { - scf_vector_free(dominators_normal); - dominators_normal = NULL; - } else { - scf_vector_free(bb->dominators_normal); - bb->dominators_normal = dominators_normal; - dominators_normal = NULL; - ++changed; - } } + + scf_vector_free(bb->dominators_normal); + bb->dominators_normal = dominators_normal; + dominators_normal = NULL; } } while (changed > 0); #if 0 diff --git a/core/scf_variable.c b/core/scf_variable.c index 1bb4ced..9ef8d2c 100644 --- a/core/scf_variable.c +++ b/core/scf_variable.c @@ -232,7 +232,6 @@ scf_variable_t* scf_variable_clone(scf_variable_t* v) v2->const_literal_flag = v->const_literal_flag; v2->const_flag = v->const_flag; v2->static_flag = v->static_flag; - v2->alloc_flag = v->alloc_flag; v2->tmp_flag = v->tmp_flag; v2->local_flag = v->local_flag; v2->global_flag = v->global_flag; @@ -284,32 +283,6 @@ void scf_variable_add_array_dimention(scf_variable_t* var, int dimention_size) var->dimentions[var->nb_dimentions++] = dimention_size; } -void scf_variable_alloc_space(scf_variable_t* var) -{ - assert(var); - if (var->alloc_flag) - return; - - if (var->nb_dimentions > 0) { - int i; - int n = 1; - for (i = 0; i < var->nb_dimentions; i++) { - assert(var->dimentions[i] > 0); - n *= var->dimentions[i]; - } - var->capacity = n; - - var->data.p = calloc(n, var->size); - assert(var->data.p); - var->alloc_flag = 1; - - } else if (var->type >= SCF_STRUCT) { - var->data.p = calloc(1, var->size); - assert(var->data.p); - var->alloc_flag = 1; - } -} - void scf_variable_get_array_member(scf_variable_t* array, int index, scf_variable_t* member) { assert(array); diff --git a/core/scf_variable.h b/core/scf_variable.h index 934595a..212c6bc 100644 --- a/core/scf_variable.h +++ b/core/scf_variable.h @@ -5,7 +5,6 @@ #include"scf_lex_word.h" struct scf_variable_s { - scf_list_t list; // for variable scope int refs; // reference count @@ -47,7 +46,6 @@ struct scf_variable_s { uint32_t const_flag :1; uint32_t static_flag :1; uint32_t extern_flag :1; - uint32_t alloc_flag :1; uint32_t extra_flag :1; uint32_t tmp_flag :1; @@ -90,8 +88,6 @@ void scf_variable_print(scf_variable_t* var); void scf_variable_add_array_dimention(scf_variable_t* var, int dimention_size); -void scf_variable_alloc_space(scf_variable_t* var); - void scf_variable_set_array_member(scf_variable_t* array, int index, scf_variable_t* member); void scf_variable_get_array_member(scf_variable_t* array, int index, scf_variable_t* member); -- 2.25.1