Commit 1f55516e authored by Matthias Braun's avatar Matthias Braun
Browse files

irmode: rename reference_mode_unsigned_eq to reference_offset_mode

Also choose a signed integer type which is more typical for offsets.
parent 00a4e075
......@@ -354,14 +354,15 @@ FIRM_API int mode_overflow_on_unary_Minus(const ir_mode *mode);
FIRM_API int mode_wrap_around(const ir_mode *mode);
/**
* Returns the unsigned integer equivalent mode for an reference mode.
* Returns the integer equivalent mode for an reference mode. This is typically
* used to add/subtract offsets from reference values.
*/
FIRM_API ir_mode *get_reference_mode_unsigned_eq(const ir_mode *mode);
FIRM_API ir_mode *get_reference_offset_mode(const ir_mode *mode);
/**
* Sets the unsigned integer equivalent mode for an reference mode.
* Sets the (signed) integer equivalent mode for an reference mode.
*/
FIRM_API void set_reference_mode_unsigned_eq(ir_mode *ref_mode, ir_mode *int_mode);
FIRM_API void set_reference_offset_mode(ir_mode *ref_mode, ir_mode *int_mode);
/**
* Returns size of bits used for to encode the mantissa (for float modes).
......
......@@ -705,7 +705,7 @@ static void create_stores_for_type(ir_graph *irg, ir_type *type)
ir_node *mem0 = new_r_Proj(store0, mode_M, pn_Store_M);
size_t offset = get_mode_size_bits(mode)/8;
ir_mode *mode_ref = get_irn_mode(addr);
ir_mode *mode_offs = get_reference_mode_unsigned_eq(mode_ref);
ir_mode *mode_offs = get_reference_offset_mode(mode_ref);
ir_node *cnst = new_r_Const_long(irg, mode_offs, offset);
ir_node *next_addr = new_r_Add(start_block, addr, cnst, mode_ref);
ir_node *store1 = new_r_Store(start_block, mem0, next_addr, val1,
......
......@@ -978,7 +978,7 @@ static void write_mode(write_env_t *env, ir_mode *mode)
write_unsigned(env, get_mode_size_bits(mode));
write_unsigned(env, get_mode_modulo_shift(mode));
write_mode_ref(env, get_reference_mode_unsigned_eq(mode));
write_mode_ref(env, get_reference_offset_mode(mode));
write_int(env, (mode == mode_P ? 1 : 0));
} else if (mode_is_float(mode)) {
write_symbol(env, "float_mode");
......@@ -2165,7 +2165,7 @@ static void read_modes(read_env_t *env)
int size = read_long(env);
unsigned modulo_shift = read_long(env);
ir_mode *mode = new_reference_mode(name, arith, size, modulo_shift);
set_reference_mode_unsigned_eq(mode, read_mode_ref(env));
set_reference_offset_mode(mode, read_mode_ref(env));
int is_mode_P = read_int(env);
if (is_mode_P)
set_modeP(mode);
......
......@@ -159,13 +159,14 @@ ir_mode *new_reference_mode(const char *name, ir_mode_arithmetic arithmetic,
0, modulo_shift);
ir_mode *res = register_mode(result);
/* construct the unsigned_eq mode */
char buf[64];
snprintf(buf, sizeof(buf), "%s_iu", name);
ir_mode *unsigned_eq = alloc_mode(buf, irms_int_number, arithmetic,
bit_size, 0, modulo_shift);
unsigned_eq = register_mode(unsigned_eq);
set_reference_mode_unsigned_eq(res, unsigned_eq);
/* Construct offset mode if none is set yet. */
if (res->offset_mode == NULL) {
char buf[64];
snprintf(buf, sizeof(buf), "%s_i", name);
ir_mode *offset_mode = new_int_mode(buf, arithmetic, bit_size, 1,
modulo_shift);
res->offset_mode = offset_mode;
}
return res;
}
......@@ -415,17 +416,18 @@ int values_in_mode(const ir_mode *sm, const ir_mode *lm)
return false;
}
ir_mode *get_reference_mode_unsigned_eq(const ir_mode *mode)
ir_mode *get_reference_offset_mode(const ir_mode *mode)
{
assert(mode_is_reference(mode));
return mode->eq_unsigned;
return mode->offset_mode;
}
void set_reference_mode_unsigned_eq(ir_mode *ref_mode, ir_mode *int_mode)
void set_reference_offset_mode(ir_mode *ref_mode, ir_mode *int_mode)
{
assert(mode_is_reference(ref_mode));
assert(mode_is_int(int_mode));
ref_mode->eq_unsigned = int_mode;
assert(get_mode_size_bits(ref_mode) == get_mode_size_bits(int_mode));
ref_mode->offset_mode = int_mode;
}
void init_mode(void)
......
......@@ -89,8 +89,9 @@ struct ir_mode {
ir_tarval *one; /**< The value 1 */
ir_tarval *all_one; /**< The value where all bits are set */
ir_tarval *infinity; /**< The (positive) infinity value */
/** For pointer modes, the equivalent unsigned integer one. */
ir_mode *eq_unsigned;
/** For reference modes, a signed integer mode used to add/subtract
* offsets. */
ir_mode *offset_mode;
};
static inline ident *get_mode_ident_(const ir_mode *mode)
......
......@@ -85,7 +85,7 @@ static void widen_builtin(ir_node *node)
return;
}
ir_mode *target_mode = get_reference_mode_unsigned_eq(mode_P);
ir_mode *target_mode = get_reference_offset_mode(mode_P);
dbg_info *dbgi = get_irn_dbg_info(node);
ir_node *block = get_nodes_block(node);
ir_node *op = get_irn_n(node, n_Builtin_max + 1);
......
......@@ -626,10 +626,9 @@ static void fix_int_return(const cl_entry *entry, ir_node *base_addr,
for (unsigned i = 0; i < n_int_rets; ++i) {
ir_node *addr = base_addr;
if (i > 0) {
ir_mode *mode_int
= get_reference_mode_unsigned_eq(mode_ref);
ir_mode *mode_offset = get_reference_offset_mode(mode_ref);
int offset = i * get_mode_size_bytes(int_return_mode);
ir_node *offset_cnst = new_r_Const_long(irg, mode_int, offset);
ir_node *offset_cnst = new_r_Const_long(irg, mode_offset, offset);
addr = new_r_Add(block, addr, offset_cnst, mode_ref);
}
ir_node *const value = new_r_Proj(proj_res, int_return_mode, pn+i);
......@@ -792,11 +791,11 @@ static void transform_return(ir_node *ret, size_t n_ret_com, wlk_env *env)
ir_node *addr = pred;
ir_mode *mode_ref = get_irn_mode(addr);
if (i > 0) {
ir_mode *mode_int
= get_reference_mode_unsigned_eq(mode_ref);
ir_mode *mode_offset
= get_reference_offset_mode(mode_ref);
int offset = i * get_mode_size_bytes(int_return_mode);
ir_node *offset_cnst
= new_r_Const_long(irg, mode_int, offset);
= new_r_Const_long(irg, mode_offset, offset);
addr = new_r_Add(block, addr, offset_cnst, mode_ref);
}
ir_node *load = new_r_Load(block, mem, addr,
......
......@@ -64,7 +64,7 @@ static void lower_small_copyb_node(ir_node *irn)
while (offset < size) {
ir_mode *mode = get_ir_mode(mode_bytes);
for (; offset + mode_bytes <= size; offset += mode_bytes) {
ir_mode *mode_ref_int = get_reference_mode_unsigned_eq(mode_ref);
ir_mode *mode_ref_int = get_reference_offset_mode(mode_ref);
/* construct offset */
ir_node *addr_const = new_r_Const_long(irg, mode_ref_int, offset);
......
......@@ -33,21 +33,21 @@ static void lower_sel(ir_node *sel)
if (element_size == 0) {
newn = ptr;
} else {
dbg_info *const dbg = get_irn_dbg_info(sel);
ir_node *const index = get_Sel_index(sel);
ir_node *const bl = get_nodes_block(sel);
ir_mode *const mode = get_irn_mode(sel);
ir_mode *const idx_mode = get_reference_mode_unsigned_eq(mode);
ir_node *const idx_conv = new_rd_Conv(dbg, bl, index, idx_mode);
dbg_info *const dbg = get_irn_dbg_info(sel);
ir_node *const index = get_Sel_index(sel);
ir_node *const bl = get_nodes_block(sel);
ir_mode *const mode = get_irn_mode(sel);
ir_mode *const offset_mode = get_reference_offset_mode(mode);
ir_node *const idx_conv = new_rd_Conv(dbg, bl, index, offset_mode);
ir_node *scaled_index;
if (element_size == 1) {
scaled_index = idx_conv;
} else {
ir_graph *const irg = get_irn_irg(sel);
ir_node *const el_size = new_rd_Const_long(dbg, irg, idx_mode,
ir_node *const el_size = new_rd_Const_long(dbg, irg, offset_mode,
element_size);
scaled_index = new_rd_Mul(dbg, bl, idx_conv, el_size, idx_mode);
scaled_index = new_rd_Mul(dbg, bl, idx_conv, el_size, offset_mode);
}
newn = new_rd_Add(dbg, bl, ptr, scaled_index, mode);
}
......@@ -75,11 +75,12 @@ static void lower_member(ir_node *member)
/* replace Member by add(ptr, const(ent.offset)) */
ir_node *newn;
if (offset != 0) {
dbg_info *const dbg = get_irn_dbg_info(member);
ir_mode *const mode = get_irn_mode(member);
ir_node *const bl = get_nodes_block(member);
ir_mode *const mode_UInt = get_reference_mode_unsigned_eq(mode);
ir_node *const cnst = new_r_Const_long(irg, mode_UInt, offset);
dbg_info *const dbg = get_irn_dbg_info(member);
ir_mode *const mode = get_irn_mode(member);
ir_node *const bl = get_nodes_block(member);
ir_mode *const mode_offset = get_reference_offset_mode(mode);
ir_node *const cnst
= new_r_Const_long(irg, mode_offset, offset);
newn = new_rd_Add(dbg, bl, ptr, cnst, mode);
} else {
newn = ptr;
......
......@@ -2111,7 +2111,7 @@ static ir_node *transform_node_AddSub(ir_node *n)
if (mode_is_signed(rmode) && get_mode_arithmetic(rmode) == irma_twos_complement) {
/* convert a AddP(P, *s) into AddP(P, *u) */
ir_mode *nm = get_reference_mode_unsigned_eq(mode);
ir_mode *nm = get_reference_offset_mode(mode);
ir_node *pre = new_r_Conv(get_nodes_block(n), right, nm);
set_binop_right(n, pre);
......@@ -2689,18 +2689,18 @@ static ir_node *transform_node_Or_(ir_node *n)
&& !mode_is_float(cmp_mode_left)
&& !mode_is_float(cmp_mode_right)) {
if (mode_is_reference(cmp_mode_left)) {
ir_mode *umode = get_reference_mode_unsigned_eq(cmp_mode_left);
ir_mode *omode = get_reference_offset_mode(cmp_mode_left);
dbg_info *dbgi = get_irn_dbg_info(a_left);
ir_node *block = get_nodes_block(n);
a_left = new_rd_Conv(dbgi, block, a_left, umode);
a_right = new_rd_Conv(dbgi, block, a_right, umode);
a_left = new_rd_Conv(dbgi, block, a_left, omode);
a_right = new_rd_Conv(dbgi, block, a_right, omode);
}
if (mode_is_reference(cmp_mode_right)) {
ir_mode *umode = get_reference_mode_unsigned_eq(cmp_mode_right);
ir_mode *omode = get_reference_offset_mode(cmp_mode_right);
dbg_info *dbgi = get_irn_dbg_info(b_left);
ir_node *block = get_nodes_block(n);
b_left = new_rd_Conv(dbgi, block, b_left, umode);
b_right = new_rd_Conv(dbgi, block, b_right, umode);
b_left = new_rd_Conv(dbgi, block, b_left, omode);
b_right = new_rd_Conv(dbgi, block, b_right, omode);
}
ir_mode *a_mode = get_irn_mode(a_left);
ir_mode *b_mode = get_irn_mode(b_left);
......@@ -4339,18 +4339,18 @@ static ir_node *transform_node_And(ir_node *n)
&& !mode_is_float(cmp_mode_left)
&& !mode_is_float(cmp_mode_right)) {
if (mode_is_reference(cmp_mode_left)) {
ir_mode *umode = get_reference_mode_unsigned_eq(cmp_mode_left);
ir_mode *omode = get_reference_offset_mode(cmp_mode_left);
dbg_info *dbgi = get_irn_dbg_info(a_left);
ir_node *block = get_nodes_block(n);
a_left = new_rd_Conv(dbgi, block, a_left, umode);
a_right = new_rd_Conv(dbgi, block, a_right, umode);
a_left = new_rd_Conv(dbgi, block, a_left, omode);
a_right = new_rd_Conv(dbgi, block, a_right, omode);
}
if (mode_is_reference(cmp_mode_right)) {
ir_mode *umode = get_reference_mode_unsigned_eq(cmp_mode_right);
ir_mode *omode = get_reference_offset_mode(cmp_mode_right);
dbg_info *dbgi = get_irn_dbg_info(b_left);
ir_node *block = get_nodes_block(n);
b_left = new_rd_Conv(dbgi, block, b_left, umode);
b_right = new_rd_Conv(dbgi, block, b_right, umode);
b_left = new_rd_Conv(dbgi, block, b_left, omode);
b_right = new_rd_Conv(dbgi, block, b_right, omode);
}
ir_mode *a_mode = get_irn_mode(a_left);
ir_mode *b_mode = get_irn_mode(b_left);
......
......@@ -539,7 +539,7 @@ static changes_t try_load_after_load(track_load_env_t *env, ir_node *prev_load)
const long delta = base_offset->offset - prev_base_offset.offset;
assert(delta <= 0);
ir_mode *const ptr_mode = get_irn_mode(prev_ptr);
ir_mode *const ptr_mode_offs = get_reference_mode_unsigned_eq(ptr_mode);
ir_mode *const ptr_mode_offs = get_reference_offset_mode(ptr_mode);
ir_node *const c = new_r_Const_long(irg, ptr_mode_offs, delta);
ir_node *const add = new_r_Add(block, prev_ptr, c, ptr_mode);
set_Load_ptr(prev_load, add);
......@@ -601,8 +601,8 @@ static bool try_update_ptr_CopyB(track_load_env_t *env, ir_node *copyb)
ir_graph *irg = get_irn_irg(load);
ir_node *block = get_nodes_block(load);
ir_mode *mode_ref = get_irn_mode(src_base_offset.base);
ir_mode *mode_ref_int = get_reference_mode_unsigned_eq(mode_ref);
ir_node *cnst = new_r_Const_long(irg, mode_ref_int,
ir_mode *mode_offset = get_reference_offset_mode(mode_ref);
ir_node *cnst = new_r_Const_long(irg, mode_offset,
src_base_offset.offset + delta);
ir_node *new_load_ptr = new_r_Add(block, src_base_offset.base, cnst, mode_P);
env->ptr = new_load_ptr;
......@@ -1426,7 +1426,7 @@ static changes_t optimize_conv_load(ir_node *conv)
ir_graph *irg = get_irn_irg(conv);
ir_node *ptr = get_Load_ptr(load);
ir_mode *mode = get_irn_mode(ptr);
ir_mode *mode_offs = get_reference_mode_unsigned_eq(mode);
ir_mode *mode_offs = get_reference_offset_mode(mode);
ir_node *delta = new_r_Const_long(irg, mode_offs, bits_diff/8);
ir_node *block = get_nodes_block(load);
ir_node *add = new_r_Add(block, ptr, delta, mode);
......
......@@ -268,8 +268,8 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env)
ir_mode *mode = modes[r];
ir_node *v = get_r_value(irg, r, mode);
if (mode_is_reference(mode)) {
ir_mode *mode_iu = get_reference_mode_unsigned_eq(mode);
v = new_r_Conv(pred_block, v, mode_iu);
ir_mode *mode_offset = get_reference_offset_mode(mode);
v = new_r_Conv(pred_block, v, mode_offset);
}
ir_node *add = new_r_Add(pred_block, pred, v, mode);
set_Return_res(ret, r, add);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment