scf_basic_block_t* bb = scf_list_data(l, scf_basic_block_t, list);
- printf("\033[33mbasic_block: %p, index: %d, dfo_normal: %d, cmp_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->group_flag, bb->loop_flag, bb->dereference_flag, bb->ret_flag);
+ 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);
scf_basic_block_print(bb, sentinel);
ret = scf_basic_block_split(bb0, &bb1); \
if (ret < 0) \
return ret; \
- bb1->call_flag = 1; \
bb1->dereference_flag = bb0->dereference_flag; \
+ bb1->ret_flag = bb0->ret_flag; \
+ bb0->ret_flag = 0; \
scf_list_add_front(&bb0->list, &bb1->list); \
scf_basic_block_mov_code(start, bb1, bb0); \
} while (0)
break;
if (l != start) {
+ bb->call_flag = 0;
SCF_BB_SPLIT_MOV_CODE(l, bb, bb_child);
bb = bb_child;
}
+ bb->call_flag = 1;
ret = __optimize_call_bb(c, bb, bb_list_head);
if (ret < 0) {
return ret;
}
-// scf_basic_block_print_list(bb_list_head);
ret = 0;
error:
return ret;
return 0;
}
+static int _alias_dereference_filter_3ac(scf_dag_node_t* dn, scf_dn_status_t* ds, scf_3ac_code_t* c, scf_basic_block_t* bb, scf_list_t* bb_list_head)
+{
+ scf_3ac_operand_t* dst;
+ scf_3ac_operand_t* src;
+ scf_3ac_code_t* c2;
+ scf_list_t* l;
+
+ int i;
+
+ for (l = scf_list_next(&c->list); l != scf_list_sentinel(&bb->code_list_head); l = scf_list_next(l)) {
+ c2 = scf_list_data(l, scf_3ac_code_t, list);
+
+ if (c2->srcs) {
+ for (i = 0; i < c2->srcs->size; i++) {
+ src = c2->srcs->data[i];
+
+ if (src->dag_node == dn)
+ src->dag_node = ds->alias;
+ }
+ }
+
+ if (c2->dsts) {
+ for (i = 0; i < c2->dsts->size; i++) {
+ dst = c2->dsts->data[i];
+
+ if (dst->dag_node == dn)
+ dst->dag_node = ds->alias;
+ }
+ }
+ }
+
+ return 0;
+}
+
static int _alias_dereference(scf_vector_t** paliases, scf_dag_node_t* dn_pointer, scf_3ac_code_t* c, scf_basic_block_t* bb, scf_list_t* bb_list_head)
{
+ scf_3ac_operand_t* dst;
+ scf_dn_status_t* ds;
scf_vector_t* aliases;
+
int ret;
aliases = scf_vector_alloc();
return ret;
}
+ if (1 == aliases->size) {
+ ds = aliases->data[0];
+
+ if (SCF_DN_ALIAS_VAR == ds->alias_type) {
+
+ dst = c->dsts->data[0];
+
+ _alias_dereference_filter_3ac(dst->dag_node, ds, c, bb, bb_list_head);
+
+ scf_vector_free(aliases);
+ aliases = NULL;
+
+ if (ret < 0)
+ return ret;
+ return scf_basic_block_inited_vars(bb, bb_list_head);
+ }
+ }
+
*paliases = aliases;
return 0;
}
int ret = 0;
- for (l = start; l != *pend; l = scf_list_next(l)) {
+ for (l = start; l != *pend; ) {
c = scf_list_data(l, scf_3ac_code_t, list);
+ l = scf_list_next(l);
if (!scf_type_is_assign_dereference(c->op->type)
&& SCF_OP_DEREFERENCE != c->op->type
}
if (flag) {
- *pend = l;
+ *pend = &c->list;
break;
}
}
return ret;
}
+// scf_basic_block_print_list(bb_list_head);
ret = 0;
error:
return ret;