-} /* lower_symconst */
-
-/**
- * Checks, whether a size is an integral size
- *
- * @param size the size on bits
- */
-static int is_integral_size(int size) {
- /* must be a 2^n */
- if (size & (size-1))
- return 0;
- /* must be at least byte size */
- return size >= 8;
-} /* is_integral_size */
-
-/**
- * lower bitfield load access.
- *
- * @param proj the Proj(result) node
- * @param load the Load node
- */
-static void lower_bitfields_loads(ir_node *proj, ir_node *load) {
- ir_node *sel = get_Load_ptr(load);
- ir_node *block, *n_proj, *res, *ptr;
- ir_entity *ent;
- ir_type *bf_type;
- ir_mode *bf_mode, *mode;
- int offset, bit_offset, bits, bf_bits, old_cse;
- dbg_info *db;
-
- if (!is_Sel(sel))
- return;
-
- ent = get_Sel_entity(sel);
- bf_type = get_entity_type(ent);
-
- /* must be a bitfield type */
- if (!is_Primitive_type(bf_type) || get_primitive_base_type(bf_type) == NULL)
- return;
-
- /* We have a bitfield access, if either a bit offset is given, or
- the size is not integral. */
- bf_mode = get_type_mode(bf_type);
- if (! bf_mode)
- return;
-
- mode = get_irn_mode(proj);
- block = get_nodes_block(proj);
- bf_bits = get_mode_size_bits(bf_mode);
- bit_offset = get_entity_offset_bits_remainder(ent);
-
- if (bit_offset == 0 && is_integral_size(bf_bits) && bf_mode == get_Load_mode(load))
- return;
-
- bits = get_mode_size_bits(mode);
- offset = get_entity_offset(ent);
-
- /*
- * ok, here we are: now convert the Proj_mode_bf(Load) into And(Shr(Proj_mode(Load)) for unsigned
- * and Shr(Shl(Proj_mode(load)) for signed
- */
-
- /* abandon bitfield sel */
- ptr = get_Sel_ptr(sel);
- db = get_irn_dbg_info(sel);
- ptr = new_rd_Add(db, current_ir_graph, block, ptr, new_Const_long(mode_Is, offset), get_irn_mode(ptr));
-
- set_Load_ptr(load, ptr);
- set_Load_mode(load, mode);
-
-
- /* create new proj, switch off CSE or we may get the old one back */
- old_cse = get_opt_cse();
- set_opt_cse(0);
- res = n_proj = new_r_Proj(current_ir_graph, block, load, mode, pn_Load_res);
- set_opt_cse(old_cse);
-
- if (mode_is_signed(mode)) { /* signed */
- int shift_count_up = bits - (bf_bits + bit_offset);
- int shift_count_down = bits - bf_bits;
-
- if (shift_count_up) {
- res = new_r_Shl(current_ir_graph, block, res,
- new_Const_long(mode_Iu, shift_count_up), mode);
- }
- if (shift_count_down) {
- res = new_r_Shrs(current_ir_graph, block, res,
- new_Const_long(mode_Iu, shift_count_down), mode);
- }
- } else { /* unsigned */
- int shift_count_down = bit_offset;
- unsigned mask = ((unsigned)-1) >> (bits - bf_bits);
-
- if (shift_count_down) {
- res = new_r_Shr(current_ir_graph, block, res,
- new_Const_long(mode_Iu, shift_count_down), mode);
- }
- if (bits != bf_bits) {
- res = new_r_And(current_ir_graph, block, res,
- new_Const_long(mode, mask), mode);
- }
- }
-
- exchange(proj, res);
-} /* lower_bitfields_loads */
-
-/**
- * lower bitfield store access.
- *
- * @todo: It adds a load which may produce an exception!
- */
-static void lower_bitfields_stores(ir_node *store) {
- ir_node *sel = get_Store_ptr(store);
- ir_node *ptr, *value;
- ir_entity *ent;
- ir_type *bf_type;
- ir_mode *bf_mode, *mode;
- ir_node *mem, *irn, *block;
- unsigned mask, neg_mask;
- int bf_bits, bits_mask, offset, bit_offset;
- dbg_info *db;
-
- /* check bitfield access */
- if (!is_Sel(sel))
- return;
-
- ent = get_Sel_entity(sel);
- bf_type = get_entity_type(ent);
-
- /* must be a bitfield type */
- if (!is_Primitive_type(bf_type) || get_primitive_base_type(bf_type) == NULL)
- return;
-
- /* We have a bitfield access, if either a bit offset is given, or
- the size is not integral. */
- bf_mode = get_type_mode(bf_type);
- if (! bf_mode)
- return;
-
- value = get_Store_value(store);
- mode = get_irn_mode(value);
- block = get_nodes_block(store);
-
- bf_bits = get_mode_size_bits(bf_mode);
- bit_offset = get_entity_offset_bits_remainder(ent);
-
- if (bit_offset == 0 && is_integral_size(bf_bits) && bf_mode == get_irn_mode(value))
- return;
-
- /*
- * ok, here we are: now convert the Store(Sel(), value) into Or(And(Load(Sel),c), And(Value,c))
- */
- mem = get_Store_mem(store);
- offset = get_entity_offset(ent);
-
- bits_mask = get_mode_size_bits(mode) - bf_bits;
- mask = ((unsigned)-1) >> bits_mask;
- mask <<= bit_offset;
- neg_mask = ~mask;
-
- /* abandon bitfield sel */
- ptr = get_Sel_ptr(sel);
- db = get_irn_dbg_info(sel);
- ptr = new_rd_Add(db, current_ir_graph, block, ptr, new_Const_long(mode_Is, offset), get_irn_mode(ptr));
-
- if (neg_mask) {
- /* there are some bits, normal case */
- irn = new_r_Load(current_ir_graph, block, mem, ptr, mode, 0);
- mem = new_r_Proj(current_ir_graph, block, irn, mode_M, pn_Load_M);
- irn = new_r_Proj(current_ir_graph, block, irn, mode, pn_Load_res);
-
- irn = new_r_And(current_ir_graph, block, irn,
- new_Const_long(mode, neg_mask), mode);
-
- if (bit_offset > 0) {
- value = new_r_Shl(current_ir_graph, block, value,
- new_Const_long(mode_Iu, bit_offset), mode);
- }
-
- value = new_r_And(current_ir_graph, block, value,
- new_Const_long(mode, mask), mode);
-
- value = new_r_Or(current_ir_graph, block, value, irn, mode);
- }
-
- set_Store_mem(store, mem);
- set_Store_value(store, value);
- set_Store_ptr(store, ptr);
-} /* lower_bitfields_stores */
-
-/**
- * Lowers unaligned Loads.
- */
-static void lower_unaligned_Load(ir_node *load) {
- (void) load;
- /* NYI */
-}
-
-/**
- * Lowers unaligned Stores
- */
-static void lower_unaligned_Store(ir_node *store) {
- (void) store;
- /* NYI */