* @author Michael Beck
* @version $Id$
*/
-
#include "config.h"
+#include <stdbool.h>
+
#include "lowering.h"
#include "irop_t.h"
#include "irprog_t.h"
lower_intrinsics(pass->list, pass->length, pass->part_block_used);
/* probably this pass should not run again */
return 0;
-} /* pass_wrapper */
+}
/**
* Creates an ir_prog pass for lower_intrinsics.
{
struct pass_t *pass = xmalloc(sizeof(*pass) + (length-1) * sizeof(pass->list[0]));
- memset(&pass->pass, 0, sizeof(pass->pass));
- pass->pass.kind = k_ir_prog_pass;
- pass->pass.run_on_irprog = pass_wrapper;
- pass->pass.context = pass;
- pass->pass.name = name ? name : "lower_intrinsics";
-
- INIT_LIST_HEAD(&pass->pass.list);
-
memcpy(pass->list, list, sizeof(list[0]) * length);
pass->length = length;
pass->part_block_used = part_block_used;
- return &pass->pass;
+ return def_prog_pass_constructor(
+ &pass->pass, name ? name : "lower_intrinsics", pass_wrapper);
} /* lower_intrinsics_pass*/
/**
irn = new_r_Tuple(block, 1, &irn);
turn_into_tuple(call, pn_Call_max);
- set_Tuple_pred(call, pn_Call_M_regular, mem);
+ set_Tuple_pred(call, pn_Call_M, mem);
set_Tuple_pred(call, pn_Call_X_regular, reg_jmp);
set_Tuple_pred(call, pn_Call_X_except, exc_jmp);
set_Tuple_pred(call, pn_Call_T_result, irn);
- set_Tuple_pred(call, pn_Call_M_except, mem);
set_Tuple_pred(call, pn_Call_P_value_res_base, new_Bad());
} /* replace_call */
return NULL;
} /* get_const_entity */
+static bool initializer_val_is_null(ir_initializer_t *init)
+{
+ tarval *tv;
+
+ if (get_initializer_kind(init) == IR_INITIALIZER_NULL)
+ return true;
+
+ if (get_initializer_kind(init) == IR_INITIALIZER_TARVAL) {
+ tv = get_initializer_tarval_value(init);
+ } else if (get_initializer_kind(init) == IR_INITIALIZER_CONST) {
+ ir_node *irn = get_initializer_const_value(init);
+ if (!is_Const(irn))
+ return false;
+ tv = get_Const_tarval(irn);
+ } else {
+ return false;
+ }
+
+ return tarval_is_null(tv);
+}
+
/**
* Calculate the value of strlen if possible.
*
static ir_node *eval_strlen(ir_entity *ent, ir_type *res_tp) {
ir_type *tp = get_entity_type(ent);
ir_mode *mode;
- int i, n, len = -1;
+ ir_initializer_t *initializer;
+ unsigned size;
+ unsigned i;
if (! is_Array_type(tp))
return NULL;
if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
return NULL;
- n = get_compound_ent_n_values(ent);
- for (i = 0; i < n; ++i) {
- ir_node *irn = get_compound_ent_value(ent, i);
+ if (!has_entity_initializer(ent)) {
+ int len;
+ int n;
+ int i = -1;
+
+ n = get_compound_ent_n_values(ent);
+ for (i = 0; i < n; ++i) {
+ ir_node *irn = get_compound_ent_value(ent, i);
- if (! is_Const(irn))
- return NULL;
+ if (! is_Const(irn))
+ return NULL;
- if (is_Const_null(irn)) {
- /* found the length */
- len = i;
- break;
+ if (is_Const_null(irn)) {
+ /* found the length */
+ len = i;
+ break;
+ }
}
+ if (len >= 0) {
+ tarval *tv = new_tarval_from_long(len, get_type_mode(res_tp));
+ return new_Const_type(tv, res_tp);
+ }
+ return NULL;
}
- if (len >= 0) {
- tarval *tv = new_tarval_from_long(len, get_type_mode(res_tp));
- return new_Const_type(tv, res_tp);
+
+ initializer = get_entity_initializer(ent);
+ if (get_initializer_kind(initializer) != IR_INITIALIZER_COMPOUND)
+ return NULL;
+
+ size = get_initializer_compound_n_entries(initializer);
+ for (i = 0; i < size; ++i) {
+ ir_initializer_t *val = get_initializer_compound_value(initializer, i);
+ if (initializer_val_is_null(val)) {
+ tarval *tv = new_tarval_from_long(i, get_type_mode(res_tp));
+ return new_Const_type(tv, res_tp);
+ }
}
+
return NULL;
} /* eval_strlen */
if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
return NULL;
- n = get_compound_ent_n_values(left);
- n_r = get_compound_ent_n_values(right);
- if (n_r < n)
- n = n_r;
- for (i = 0; i < n; ++i) {
- ir_node *irn;
- long v_l, v_r;
- tarval *tv;
-
- irn = get_compound_ent_value(left, i);
- if (! is_Const(irn))
- return NULL;
- tv = get_Const_tarval(irn);
- v_l = get_tarval_long(tv);
-
- irn = get_compound_ent_value(right, i);
- if (! is_Const(irn))
- return NULL;
- tv = get_Const_tarval(irn);
- v_r = get_tarval_long(tv);
+ if (!has_entity_initializer(left) && !has_entity_initializer(right)) {
+ /* code that uses deprecated compound_graph_path stuff */
+
+ n = get_compound_ent_n_values(left);
+ n_r = get_compound_ent_n_values(right);
+ if (n_r < n)
+ n = n_r;
+ for (i = 0; i < n; ++i) {
+ ir_node *irn;
+ long v_l, v_r;
+ tarval *tv;
+
+ irn = get_compound_ent_value(left, i);
+ if (! is_Const(irn))
+ return NULL;
+ tv = get_Const_tarval(irn);
+ v_l = get_tarval_long(tv);
+
+ irn = get_compound_ent_value(right, i);
+ if (! is_Const(irn))
+ return NULL;
+ tv = get_Const_tarval(irn);
+ v_r = get_tarval_long(tv);
+
+ if (v_l < v_r) {
+ res = -1;
+ break;
+ }
+ if (v_l > v_r) {
+ res = +1;
+ break;
+ }
- if (v_l < v_r) {
- res = -1;
- break;
- }
- if (v_l > v_r) {
- res = +1;
- break;
+ if (v_l == 0) {
+ res = 0;
+ break;
+ }
}
-
- if (v_l == 0) {
- res = 0;
- break;
+ if (i < n) {
+ /* we found an end */
+ tarval *tv = new_tarval_from_long(res, get_type_mode(res_tp));
+ return new_Const_type(tv, res_tp);
}
+ return NULL;
}
- if (i < n) {
- /* we found an end */
- tarval *tv = new_tarval_from_long(res, get_type_mode(res_tp));
- return new_Const_type(tv, res_tp);
- }
+
+ /* TODO */
+
return NULL;
} /* eval_strcmp */
* @return non-zero if ent represents the empty string
*/
static int is_empty_string(ir_entity *ent) {
- ir_type *tp = get_entity_type(ent);
- ir_mode *mode;
- int n;
- ir_node *irn;
+ ir_type *tp = get_entity_type(ent);
+ ir_mode *mode;
+ ir_node *irn;
+ ir_initializer_t *initializer;
+ ir_initializer_t *init0;
if (! is_Array_type(tp))
return 0;
if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
return 0;
- n = get_compound_ent_n_values(ent);
- if (n < 1)
+ if (!has_entity_initializer(ent)) {
+ /* code for deprecated compound_graph_path stuff */
+ int n = get_compound_ent_n_values(ent);
+ if (n < 1)
+ return 0;
+ irn = get_compound_ent_value(ent, 0);
+
+ return is_Const(irn) && is_Const_null(irn);
+ }
+
+ initializer = get_entity_initializer(ent);
+ if (get_initializer_kind(initializer) != IR_INITIALIZER_COMPOUND)
+ return 0;
+
+ if (get_initializer_compound_n_entries(initializer) < 1)
return 0;
- irn = get_compound_ent_value(ent, 0);
- return is_Const(irn) && is_Const_null(irn);
+ init0 = get_initializer_compound_value(initializer, 0);
+ return initializer_val_is_null(init0);
} /* is_empty_string */
/* A mapper for strcmp */
for (i = 0; i < n_proj; ++i)
set_Tuple_pred(node, i, new_r_Bad(irg));
if (rt->mem_proj_nr >= 0)
- set_Tuple_pred(node, rt->mem_proj_nr, new_r_Proj(bl, call, mode_M, pn_Call_M_regular));
+ set_Tuple_pred(node, rt->mem_proj_nr, new_r_Proj(bl, call, mode_M, pn_Call_M));
if (!is_NoMem(mem)) {
/* Exceptions can only be handled with real memory */
if (rt->regular_proj_nr >= 0)
if (rt->exc_proj_nr >= 0)
set_Tuple_pred(node, rt->exc_proj_nr, new_r_Proj(bl, call, mode_X, pn_Call_X_except));
if (rt->exc_mem_proj_nr >= 0)
- set_Tuple_pred(node, rt->mem_proj_nr, new_r_Proj(bl, call, mode_M, pn_Call_M_except));
+ set_Tuple_pred(node, rt->mem_proj_nr, new_r_Proj(bl, call, mode_M, pn_Call_M));
}
if (rt->res_proj_nr >= 0)