#include "tv.h"
#include "error.h"
#include "lowering.h"
-#include "benode_t.h"
static ir_mode *lowered_mode = NULL;
static int lower_direct_cmp = 0;
+static ir_type *lowered_type = NULL;
static ir_node *create_not(dbg_info *dbgi, ir_node *node)
{
return conv;
}
-static ir_node *create_conv_lowered_mode(ir_node *node)
+static ir_type *create_lowered_type(void)
{
- ir_graph *irg = current_ir_graph;
- ir_node *block = get_nodes_block(node);
- ir_node *conv = new_rd_Conv(NULL, irg, block, node, lowered_mode);
+ if(lowered_type == NULL) {
+ lowered_type = new_type_primitive(new_id_from_str("__lowered_mode_b"),
+ lowered_mode);
+ }
+ return lowered_type;
+}
- return conv;
+static void adjust_method_type(ir_type *method_type)
+{
+ int i;
+ int n_params;
+ int n_res;
+
+ n_params = get_method_n_params(method_type);
+ for(i = 0; i < n_params; ++i) {
+ ir_type *param = get_method_param_type(method_type, i);
+ if(get_type_mode(param) == mode_b) {
+ set_method_param_type(method_type, i, create_lowered_type());
+ }
+ }
+
+ n_res = get_method_n_ress(method_type);
+ for(i = 0; i < n_res; ++i) {
+ ir_type *res_type = get_method_res_type(method_type, i);
+ if(get_type_mode(res_type) == mode_b) {
+ set_method_res_type(method_type, i, create_lowered_type());
+ }
+ }
}
static ir_node *lower_node(ir_node *node)
return psi;
}
if(op == op_Proj) {
- ir_node *pred = get_Proj_pred(node);
+ ir_node *pred = get_Proj_pred(node);
- assert(!is_Load(pred));
if(is_Cmp(pred)) {
- ir_mode *mode = get_irn_mode(pred);
ir_node *left = get_Cmp_left(pred);
ir_node *right = get_Cmp_right(pred);
+ ir_mode *mode = get_irn_mode(left);
- if( (mode_is_int(mode) || mode_is_reference(mode)) &&
- (get_mode_size_bits(mode) < get_mode_size_bits(lowered_mode)
- || classify_Const(right) == CNST_NULL)) {
+ if ((mode_is_int(mode) || mode_is_reference(mode)) && (
+ get_mode_size_bits(mode) < get_mode_size_bits(lowered_mode) ||
+ (is_Const(right) && is_Const_null(right))
+ )) {
int pnc = get_Proj_proj(node);
- int need_not = 0;
+ int need_neg = 0;
ir_node *a = NULL;
ir_node *b = NULL;
a = left;
b = right;
} else if(pnc == pn_Cmp_Le) {
- /* a <= b -> ((a - b) >> 31) ^ 1 */
+ /* a <= b -> ~(a - b) >> 31 */
a = right;
b = left;
- need_not = 1;
+ need_neg = 1;
} else if(pnc == pn_Cmp_Gt) {
/* a > b -> (b - a) >> 31 */
a = right;
b = left;
} else if(pnc == pn_Cmp_Ge) {
- /* a >= b -> ((a - b) >> 31) ^ 1 */
+ /* a >= b -> ~(a - b) >> 31 */
a = left;
b = right;
- need_not = 1;
+ need_neg = 1;
}
if(a != NULL) {
}
res = new_rd_Sub(dbgi, irg, block, a, b, lowered_mode);
+ if(need_neg) {
+ res = new_rd_Not(dbgi, irg, block, res, lowered_mode);
+ }
res = new_rd_Shr(dbgi, irg, block, res, shift_cnt,
lowered_mode);
- if(need_not) {
- res = create_not(dbgi, res);
- }
set_irn_link(node, res);
return res;
}
return psi;
}
} else if(is_Proj(pred) && is_Call(get_Proj_pred(pred))) {
- return create_conv_lowered_mode(node);
+ ir_type *type = get_Call_type(get_Proj_pred(pred));
+ adjust_method_type(type);
+ set_irn_mode(node, lowered_mode);
+ return node;
} else if(is_Proj(pred) && is_Start(get_Proj_pred(pred))) {
- return create_conv_lowered_mode(node);
- } else if (be_is_Barrier(pred)) {
- /* nothing to do */
+ ir_entity *entity = get_irg_entity(irg);
+ ir_type *type = get_entity_type(entity);
+ adjust_method_type(type);
+ set_irn_mode(node, lowered_mode);
return node;
}
}
lowered_in = lower_node(in);
- lowered_in = create_convb(lowered_in);
+
+ if(is_Return(node)) {
+ ir_entity *entity = get_irg_entity(current_ir_graph);
+ ir_type *type = get_entity_type(entity);
+ adjust_method_type(type);
+ } else if(is_Call(node)) {
+ ir_type *type = get_Call_type(node);
+ adjust_method_type(type);
+ } else {
+ lowered_in = create_convb(lowered_in);
+ }
set_irn_n(node, i, lowered_in);
}
}