delete some unused code
authoryu.dongliang <18588496441@163.com>
Thu, 7 Dec 2023 06:40:07 +0000 (14:40 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 7 Dec 2023 06:40:07 +0000 (14:40 +0800)
core/scf_optimizer_dominators.c
core/scf_variable.c
core/scf_variable.h

index 3020b2f040666d36012e62b78d52b43cea91e221..e5f310ac3b57a00314b54f0d6469f003195c80e4 100644 (file)
@@ -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
index 1bb4ced4be33250fd289db5bd5708057450984f6..9ef8d2c5001168e89bc0d8a54b886c9fa80d9a6a 100644 (file)
@@ -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);
index 934595aacba7669d07180fcde003f016dbb18ecb..212c6bc8619b2abe59404dc8d3be67241e82369a 100644 (file)
@@ -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);