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;
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)
scf_list_t* l;
scf_basic_block_t* bb;
+ scf_basic_block_t* prev;
scf_vector_t* all;
int i;
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) {
}
}
- 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;
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
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;
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);
#include"scf_lex_word.h"
struct scf_variable_s {
- scf_list_t list; // for variable scope
int refs; // reference count
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;
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);