From: Michael Beck Date: Wed, 28 Nov 2007 17:38:35 +0000 (+0000) Subject: size/aligment of types is now unsigned and in bytes, this fixes fehler095.c (array... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=4ebc4b6497324aa5d2380a897c75d3c391760ba0;p=libfirm size/aligment of types is now unsigned and in bytes, this fixes fehler095.c (array to big) [r16860] --- diff --git a/include/libfirm/typerep.h b/include/libfirm/typerep.h index 930228db5..457ce3fe4 100644 --- a/include/libfirm/typerep.h +++ b/include/libfirm/typerep.h @@ -531,7 +531,7 @@ void set_array_entity_values(ir_entity *ent, tarval **values, int num_vals); * @param ent Any entity of compound type with at least pos initialization values. * @param pos The position of the value for which the offset is requested. */ -int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos); +unsigned get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos); /** Return the overall offset of value at position pos in bytes. * @@ -541,7 +541,7 @@ int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos); * @param ent Any entity of compound type with at least pos initialization values. * @param pos The position of the value for which the offset is requested. */ -int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos); +unsigned get_compound_ent_value_offset_bytes(ir_entity *ent, int pos); /* --- Fields of entities with a class type as owner --- */ /* Overwrites is a field that specifies that an access to the overwritten @@ -1331,32 +1331,21 @@ ir_mode *get_type_mode(const ir_type *tp); */ void set_type_mode(ir_type *tp, ir_mode* m); -/** Returns the size of a type in bytes, returns -1 if the size is NOT - * a byte size, i.e. not dividable by 8. */ -int get_type_size_bytes(const ir_type *tp); - -/** Returns the size of a type in bits. */ -int get_type_size_bits(const ir_type *tp); +/** Returns the size of a type in bytes. */ +unsigned get_type_size_bytes(const ir_type *tp); /** Sets the size of a type in bytes. * * For primitive, enumeration, pointer and method types the size * is always fixed. This call is legal but has no effect. */ -void set_type_size_bytes(ir_type *tp, int size); - -/** Sets the size of a type in bits. - * - * For primitive, enumeration, pointer and method types the size - * is always fixed. This call is legal but has no effect. - */ -void set_type_size_bits(ir_type *tp, int size); +void set_type_size_bytes(ir_type *tp, unsigned size); /** Returns the alignment of a type in bytes. * * Returns -1 if the alignment is NOT * a byte size, i.e. not dividable by 8. Calls get_type_alignment_bits(). */ -int get_type_alignment_bytes(ir_type *tp); +unsigned get_type_alignment_bytes(ir_type *tp); /** Returns the alignment of a type in bits. * @@ -1366,19 +1355,9 @@ int get_type_alignment_bytes(ir_type *tp); * -#.) compound types have the alignment of there biggest member. * -#.) array types have the alignment of there element type. * -#.) method types return 0 here. - * -#.) all other types return 8 here (i.e. aligned at byte). - */ -int get_type_alignment_bits(ir_type *tp); - -/** Sets the alignment of a type in bytes. */ -void set_type_alignment_bytes(ir_type *tp, int size); - -/** Sets the alignment of a type in bits. - * - * For method types the alignment is always fixed. - * This call is legal but has no effect. + * -#.) all other types return 1 here (i.e. aligned at byte). */ -void set_type_alignment_bits(ir_type *tp, int size); +void set_type_alignment_bytes(ir_type *tp, unsigned align); /** Returns the visited count of a type. */ unsigned long get_type_visited(const ir_type *tp); @@ -2399,7 +2378,7 @@ ir_type *get_associated_type(const ir_type *tp); * * @return the entity representing the area */ -ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at_start); +ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment, int at_start); /*-----------------------------------------------------------------*/ /** Debug aides **/ diff --git a/ir/be/beabi.c b/ir/be/beabi.c index b6400df39..c6050e971 100644 --- a/ir/be/beabi.c +++ b/ir/be/beabi.c @@ -1576,7 +1576,7 @@ static void fix_address_of_parameter_access(be_abi_irg_t *env, ir_entity *value_ ir_node *frame, *imem, *nmem, *store, *mem, *args, *args_bl; const ir_edge_t *edge; optimization_state_t state; - int offset; + unsigned offset; foreach_block_succ(start_bl, edge) { ir_node *succ = get_edge_src_irn(edge); @@ -1630,11 +1630,11 @@ static void fix_address_of_parameter_access(be_abi_irg_t *env, ir_entity *value_ frame_tp = get_irg_frame_type(irg); offset = get_type_size_bytes(frame_tp); for (ent = new_list; ent; ent = get_entity_link(ent)) { - ir_type *tp = get_entity_type(ent); - int align = get_type_alignment_bytes(tp); + ir_type *tp = get_entity_type(ent); + unsigned align = get_type_alignment_bytes(tp); offset += align - 1; - offset &= -align; + offset &= ~(align - 1); set_entity_owner(ent, frame_tp); add_class_member(frame_tp, ent); /* must be automatic to set a fixed layout */ @@ -2211,10 +2211,10 @@ static int process_stack_bias(be_abi_irg_t *env, ir_node *bl, int bias) if(be_is_IncSP(irn)) { if(ofs == BE_STACK_FRAME_SIZE_EXPAND) { - ofs = get_type_size_bytes(get_irg_frame_type(env->birg->irg)); + ofs = (int)get_type_size_bytes(get_irg_frame_type(env->birg->irg)); be_set_IncSP_offset(irn, ofs); } else if(ofs == BE_STACK_FRAME_SIZE_SHRINK) { - ofs = - get_type_size_bytes(get_irg_frame_type(env->birg->irg)); + ofs = - (int)get_type_size_bytes(get_irg_frame_type(env->birg->irg)); be_set_IncSP_offset(irn, ofs); } } diff --git a/ir/be/begnuas.c b/ir/be/begnuas.c index df927d554..208603d0c 100644 --- a/ir/be/begnuas.c +++ b/ir/be/begnuas.c @@ -294,11 +294,11 @@ static void do_dump_atomic_init(be_gas_decl_env_t *env, obstack_t *obst, break; case symconst_type_size: - obstack_printf(obst, "%d", get_type_size_bytes(get_SymConst_type(init))); + obstack_printf(obst, "%u", get_type_size_bytes(get_SymConst_type(init))); break; case symconst_type_align: - obstack_printf(obst, "%d", get_type_alignment_bytes(get_SymConst_type(init))); + obstack_printf(obst, "%u", get_type_alignment_bytes(get_SymConst_type(init))); break; case symconst_enum_const: @@ -519,17 +519,17 @@ static void dump_compound_init(be_gas_decl_env_t *env, obstack_t *obst, { normal_or_bitfield *vals; int i, j, n = get_compound_ent_n_values(ent); - int last_ofs; + unsigned k, last_ofs; /* Find the initializer size. Sorrily gcc support a nasty feature: The last field of a compound may be a flexible array. This allows initializers bigger than the type size. */ last_ofs = get_type_size_bytes(get_entity_type(ent)); for (i = 0; i < n; ++i) { - int offset = get_compound_ent_value_offset_bytes(ent, i); - int bits_remainder = get_compound_ent_value_offset_bit_remainder(ent, i); - ir_node *value = get_compound_ent_value(ent, i); - int value_len = get_mode_size_bits(get_irn_mode(value)); + unsigned offset = get_compound_ent_value_offset_bytes(ent, i); + unsigned bits_remainder = get_compound_ent_value_offset_bit_remainder(ent, i); + ir_node *value = get_compound_ent_value(ent, i); + unsigned value_len = get_mode_size_bits(get_irn_mode(value)); offset += (value_len + bits_remainder + 7) >> 3; @@ -546,33 +546,33 @@ static void dump_compound_init(be_gas_decl_env_t *env, obstack_t *obst, /* collect the values and store them at the offsets */ for (i = 0; i < n; ++i) { - int offset = get_compound_ent_value_offset_bytes(ent, i); - int offset_bits = get_compound_ent_value_offset_bit_remainder(ent, i); - ir_node *value = get_compound_ent_value(ent, i); - int value_len = get_mode_size_bits(get_irn_mode(value)); - assert(offset >= 0); + unsigned offset = get_compound_ent_value_offset_bytes(ent, i); + int offset_bits = get_compound_ent_value_offset_bit_remainder(ent, i); + ir_node *value = get_compound_ent_value(ent, i); + int value_len = get_mode_size_bits(get_irn_mode(value)); + assert(offset_bits >= 0); if (offset_bits != 0 || (value_len != 8 && value_len != 16 && value_len != 32 && value_len != 64)) { tarval *tv = get_atomic_init_tv(value); - unsigned char curr_bits, last_bits = 0; + unsigned char curr_bits, last_bits = 0; if (tv == NULL) { panic("Couldn't get numeric value for bitfield initializer '%s'\n", get_entity_ld_name(ent)); } - /* normalize offset */ - offset += offset_bits >> 3; - offset_bits &= 7; + /* normalize offset */ + offset += offset_bits >> 3; + offset_bits &= 7; for (j = 0; value_len + offset_bits > 0; ++j) { assert(offset + j < last_ofs); assert(vals[offset + j].kind == BITFIELD || vals[offset + j].v.value == NULL); vals[offset + j].kind = BITFIELD; - curr_bits = get_tarval_sub_bits(tv, j); + curr_bits = get_tarval_sub_bits(tv, j); vals[offset + j].v.bf_val |= (last_bits >> (8 - offset_bits)) | (curr_bits << offset_bits); value_len -= 8; - last_bits = curr_bits; + last_bits = curr_bits; } } else { int i; @@ -587,24 +587,24 @@ static void dump_compound_init(be_gas_decl_env_t *env, obstack_t *obst, } /* now write them sorted */ - for (i = 0; i < last_ofs; ) { + for (k = 0; k < last_ofs; ) { int space = 0, skip = 0; - if (vals[i].kind == NORMAL) { - if(vals[i].v.value != NULL) { - dump_atomic_init(env, obst, vals[i].v.value); - skip = get_mode_size_bytes(get_irn_mode(vals[i].v.value)) - 1; + if (vals[k].kind == NORMAL) { + if(vals[k].v.value != NULL) { + dump_atomic_init(env, obst, vals[k].v.value); + skip = get_mode_size_bytes(get_irn_mode(vals[k].v.value)) - 1; } else { space = 1; } } else { - assert(vals[i].kind == BITFIELD); - obstack_printf(obst, "\t.byte\t%d\n", vals[i].v.bf_val); + assert(vals[k].kind == BITFIELD); + obstack_printf(obst, "\t.byte\t%d\n", vals[k].v.bf_val); } - ++i; - while (i < last_ofs && vals[i].kind == NORMAL && vals[i].v.value == NULL) { + ++k; + while (k < last_ofs && vals[k].kind == NORMAL && vals[k].v.value == NULL) { ++space; - ++i; + ++k; } space -= skip; assert(space >= 0); @@ -628,7 +628,7 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons obstack_t *obst; ir_type *type = get_entity_type(ent); const char *ld_name = get_entity_ld_name(ent); - int align = get_type_alignment_bytes(type); + unsigned align = get_type_alignment_bytes(type); int emit_as_common = 0; ir_variability variability; ir_visibility visibility; @@ -637,7 +637,7 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons if (is_Method_type(type)) { if (get_method_img_section(ent) == section_constructors) { obst = env->ctor_obst; - obstack_printf(obst, ".balign\t%d\n", align); + obstack_printf(obst, ".balign\t%u\n", align); dump_size_type(obst, align); obstack_printf(obst, "%s\n", ld_name); } @@ -668,7 +668,7 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons } /* alignment */ if (align > 1 && !emit_as_common) { - obstack_printf(obst, ".balign\t%d\n", align); + obstack_printf(obst, ".balign\t%u\n", align); } if (!emit_as_common) { @@ -678,13 +678,13 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons if (variability == variability_uninitialized) { if(emit_as_common) { if (be_gas_flavour == GAS_FLAVOUR_NORMAL) - obstack_printf(obst, "\t.comm %s,%d,%d\n", + obstack_printf(obst, "\t.comm %s,%u,%u\n", ld_name, get_type_size_bytes(type), align); else - obstack_printf(obst, "\t.comm %s,%d # %d\n", + obstack_printf(obst, "\t.comm %s,%u # %u\n", ld_name, get_type_size_bytes(type), align); } else { - obstack_printf(obst, "\t.zero %d\n", get_type_size_bytes(type)); + obstack_printf(obst, "\t.zero %u\n", get_type_size_bytes(type)); } } else { if (is_atomic_entity(ent)) { diff --git a/ir/be/benode.c b/ir/be/benode.c index 0646ebfba..7df31e3e6 100644 --- a/ir/be/benode.c +++ b/ir/be/benode.c @@ -1657,9 +1657,9 @@ static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason) if(be_has_frame_entity(irn)) { be_frame_attr_t *a = (be_frame_attr_t *) at; if (a->ent) { - int bits = get_type_size_bits(get_entity_type(a->ent)); - ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bits\n", - a->ent, a->offset, a->offset, bits, bits); + unsigned size = get_type_size_bytes(get_entity_type(a->ent)); + ir_fprintf(f, "frame entity: %+F, offset 0x%x (%d), size 0x%x (%d) bytes\n", + a->ent, a->offset, a->offset, size, size); } } diff --git a/ir/be/bestabs.c b/ir/be/bestabs.c index cc68b6741..b268c389e 100644 --- a/ir/be/bestabs.c +++ b/ir/be/bestabs.c @@ -353,7 +353,8 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) { for (i = 0, n = get_compound_n_members(tp); i < n; ++i) { ir_entity *ent = get_compound_member(tp, i); ir_type *mtp = get_entity_type(ent); - int ofs, size; + int ofs; + unsigned size; if (! IS_TYPE_READY(mtp)) waitq_put(env->wq, mtp); @@ -368,11 +369,11 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) { int bofs; type_num = get_type_number(h, tp); - size = get_type_size_bits(tp); + size = get_type_size_bytes(tp) * 8; bofs = (ofs + get_entity_offset(ent)) * 8 + get_entity_offset_bits_remainder(ent); /* name:type, bit offset from the start of the struct', number of bits in the element. */ - fprintf(h->f, "%s:%u,%d,%d;", get_entity_name(ent), type_num, bofs, size); + fprintf(h->f, "%s:%u,%d,%u;", get_entity_name(ent), type_num, bofs, size); } } else { /* no bitfield */ @@ -390,8 +391,8 @@ static void gen_struct_union_type(wenv_t *env, ir_type *tp) { /* name:type, bit offset from the start of the struct', number of bits in the element. */ fprintf(h->f, "%u", type_num); } - size = get_type_size_bits(mtp); - fprintf(h->f, ",%d,%d;", ofs * 8, size); + size = get_type_size_bytes(mtp) * 8; + fprintf(h->f, ",%d,%u;", ofs * 8, size); } } fprintf(h->f, ";\",%d,0,0,0\n", N_LSYM); diff --git a/ir/be/ia32/bearch_ia32.c b/ir/be/ia32/bearch_ia32.c index d2c871340..e2288b507 100644 --- a/ir/be/ia32/bearch_ia32.c +++ b/ir/be/ia32/bearch_ia32.c @@ -1293,25 +1293,25 @@ static void transform_MemPerm(ia32_code_gen_t *cg, ir_node *node) { arity = be_get_MemPerm_entity_arity(node); pops = alloca(arity * sizeof(pops[0])); - // create pushs + /* create Pushs */ for(i = 0; i < arity; ++i) { ir_entity *inent = be_get_MemPerm_in_entity(node, i); ir_entity *outent = be_get_MemPerm_out_entity(node, i); ir_type *enttype = get_entity_type(inent); - int entbits = get_type_size_bits(enttype); - int entbits2 = get_type_size_bits(get_entity_type(outent)); + unsigned entsize = get_type_size_bytes(enttype); + unsigned entsize2 = get_type_size_bytes(get_entity_type(outent)); ir_node *mem = get_irn_n(node, i + 1); ir_node *push; /* work around cases where entities have different sizes */ - if(entbits2 < entbits) - entbits = entbits2; - assert( (entbits == 32 || entbits == 64) && "spillslot on x86 should be 32 or 64 bit"); + if(entsize2 < entsize) + entsize = entsize2; + assert( (entsize == 4 || entsize == 8) && "spillslot on x86 should be 32 or 64 bit"); push = create_push(cg, node, node, sp, mem, inent); sp = create_spproj(cg, node, push, pn_ia32_Push_stack); - if(entbits == 64) { - // add another push after the first one + if(entsize == 8) { + /* add another push after the first one */ push = create_push(cg, node, node, sp, mem, inent); add_ia32_am_offs_int(push, 4); sp = create_spproj(cg, node, push, pn_ia32_Push_stack); @@ -1320,26 +1320,26 @@ static void transform_MemPerm(ia32_code_gen_t *cg, ir_node *node) { set_irn_n(node, i, new_Bad()); } - // create pops + /* create pops */ for(i = arity - 1; i >= 0; --i) { ir_entity *inent = be_get_MemPerm_in_entity(node, i); ir_entity *outent = be_get_MemPerm_out_entity(node, i); ir_type *enttype = get_entity_type(outent); - int entbits = get_type_size_bits(enttype); - int entbits2 = get_type_size_bits(get_entity_type(inent)); + unsigned entsize = get_type_size_bytes(enttype); + unsigned entsize2 = get_type_size_bytes(get_entity_type(inent)); ir_node *pop; /* work around cases where entities have different sizes */ - if(entbits2 < entbits) - entbits = entbits2; - assert( (entbits == 32 || entbits == 64) && "spillslot on x86 should be 32 or 64 bit"); + if(entsize2 < entsize) + entsize = entsize2; + assert( (entsize == 4 || entsize == 8) && "spillslot on x86 should be 32 or 64 bit"); pop = create_pop(cg, node, node, sp, outent); sp = create_spproj(cg, node, pop, pn_ia32_Pop_stack); - if(entbits == 64) { + if(entsize == 8) { add_ia32_am_offs_int(pop, 4); - // add another pop after the first one + /* add another pop after the first one */ pop = create_pop(cg, node, node, sp, outent); sp = create_spproj(cg, node, pop, pn_ia32_Pop_stack); } @@ -1351,7 +1351,7 @@ static void transform_MemPerm(ia32_code_gen_t *cg, ir_node *node) { keep = be_new_Keep(&ia32_reg_classes[CLASS_ia32_gp], irg, block, 1, in); sched_add_before(node, keep); - // exchange memprojs + /* exchange memprojs */ foreach_out_edge_safe(node, edge, next) { ir_node *proj = get_edge_src_irn(edge); int p = get_Proj_proj(proj); @@ -1362,7 +1362,7 @@ static void transform_MemPerm(ia32_code_gen_t *cg, ir_node *node) { set_Proj_proj(proj, pn_ia32_Pop_M); } - // remove memperm + /* remove memperm */ arity = get_irn_arity(node); for(i = 0; i < arity; ++i) { set_irn_n(node, i, new_Bad()); diff --git a/ir/ir/irdumptxt.c b/ir/ir/irdumptxt.c index 83b80e081..82a67d200 100644 --- a/ir/ir/irdumptxt.c +++ b/ir/ir/irdumptxt.c @@ -668,9 +668,9 @@ void dump_entity_to_file_prefix(FILE *F, ir_entity *ent, char *prefix, unsigned for (i = 0; i < get_compound_ent_n_values(ent); ++i) { compound_graph_path *path = get_compound_ent_value_path(ent, i); ir_entity *ent0 = get_compound_graph_path_node(path, 0); - fprintf(F, "\n%s %3d:%d ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0)); + fprintf(F, "\n%s %3d:%u ", prefix, get_entity_offset(ent0), get_entity_offset_bits_remainder(ent0)); if (get_type_state(type) == layout_fixed) - fprintf(F, "(%3d:%d) ", get_compound_ent_value_offset_bytes(ent, i), get_compound_ent_value_offset_bit_remainder(ent, i)); + fprintf(F, "(%3u:%u) ", get_compound_ent_value_offset_bytes(ent, i), get_compound_ent_value_offset_bit_remainder(ent, i)); fprintf(F, "%s", get_entity_name(ent)); for (j = 0; j < get_compound_graph_path_length(path); ++j) { ir_entity *node = get_compound_graph_path_node(path, j); @@ -1217,8 +1217,8 @@ void dump_type_to_file(FILE *F, ir_type *tp, dump_verbosity verbosity) { fprintf(F, " visibility: %s,\n", get_visibility_name(get_type_visibility(tp))); fprintf(F, " state: %s,\n", get_type_state_name(get_type_state(tp))); - fprintf(F, " size: %2d Bits,\n", get_type_size_bits(tp)); - fprintf(F, " alignment: %2d Bits,\n", get_type_alignment_bits(tp)); + fprintf(F, " size: %2u Bytes,\n", get_type_size_bytes(tp)); + fprintf(F, " alignment: %2u Bytes,\n", get_type_alignment_bytes(tp)); if (is_atomic_type(tp) || is_Method_type(tp)) fprintf(F, " mode: %s,\n", get_mode_name(get_type_mode(tp))); diff --git a/ir/ir/irprofile.c b/ir/ir/irprofile.c index 69d3098eb..c6595d149 100644 --- a/ir/ir/irprofile.c +++ b/ir/ir/irprofile.c @@ -337,7 +337,7 @@ ir_profile_instrument(const char *filename, unsigned flags) tarval *tv; int filename_len = strlen(filename)+1; ident *cur_ident; - int align_l, align_n, size; + unsigned align_l, align_n, size; ir_graph *rem; block_id_walker_data_t wd; symconst_symbol sym; diff --git a/ir/opt/escape_ana.c b/ir/opt/escape_ana.c index b58f8b11b..f486ed4ce 100644 --- a/ir/opt/escape_ana.c +++ b/ir/opt/escape_ana.c @@ -385,7 +385,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) if (tv != tarval_bad && tarval_is_long(tv) && get_type_state(atp) == layout_fixed && - get_tarval_long(tv) == get_type_size_bytes(atp)) { + (unsigned)get_tarval_long(tv) == get_type_size_bytes(atp)) { /* a already lowered type size */ tp = atp; } diff --git a/ir/tr/entity.c b/ir/tr/entity.c index e10348a13..b2f51d073 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -986,10 +986,10 @@ set_array_entity_values(ir_entity *ent, tarval **values, int num_vals) { } /* set_array_entity_values */ /* Return the overall offset of value at position pos in bytes. */ -int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) { +unsigned get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) { compound_graph_path *path; int path_len, i; - int offset = 0; + unsigned offset = 0; ir_type *curr_tp; assert(get_type_state(get_entity_type(ent)) == layout_fixed); @@ -1001,16 +1001,14 @@ int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) { for (i = 0; i < path_len; ++i) { if (is_Array_type(curr_tp)) { ir_type *elem_type = get_array_element_type(curr_tp); - int size = get_type_size_bits(elem_type); - int align = get_type_alignment_bits(elem_type); + unsigned size = get_type_size_bytes(elem_type); + unsigned align = get_type_alignment_bytes(elem_type); int idx; assert(size > 0); if(size % align > 0) { size += align - (size % align); } - assert(size % 8 == 0); - size /= 8; idx = get_compound_graph_path_array_index(path, i); assert(idx >= 0); offset += size * idx; @@ -1026,7 +1024,7 @@ int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos) { } /* get_compound_ent_value_offset_bytes */ /* Return the offset in bits from the last byte address. */ -int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) { +unsigned get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos) { compound_graph_path *path; int path_len; ir_entity *last_node; diff --git a/ir/tr/tpop.c b/ir/tr/tpop.c index 015d1cd4f..62d247c34 100644 --- a/ir/tr/tpop.c +++ b/ir/tr/tpop.c @@ -75,7 +75,7 @@ static const tp_op_ops free_class_entities, NULL, set_class_mode, - set_class_size_bits, + set_class_size, get_class_n_members, get_class_member, get_class_member_index @@ -86,7 +86,7 @@ static const tp_op_ops free_struct_entities, NULL, set_struct_mode, - set_struct_size_bits, + set_struct_size, get_struct_n_members, get_struct_member, get_struct_member_index @@ -108,7 +108,7 @@ static const tp_op_ops free_union_entities, NULL, NULL, - set_union_size_bits, + set_union_size, get_union_n_members, get_union_member, get_union_member_index @@ -119,7 +119,7 @@ static const tp_op_ops free_array_entities, free_array_automatic_entities, NULL, - set_array_size_bits, + set_array_size, NULL, NULL, NULL @@ -152,7 +152,7 @@ static const tp_op_ops NULL, NULL, NULL, - set_default_size_bits, + set_default_size, NULL, NULL, NULL diff --git a/ir/tr/tpop_t.h b/ir/tr/tpop_t.h index 29e7ae616..becb169f6 100644 --- a/ir/tr/tpop_t.h +++ b/ir/tr/tpop_t.h @@ -44,8 +44,8 @@ typedef void (*free_auto_entities_func)(ir_type *tp); /** A function called to set the mode of a type. */ typedef void (*set_type_mode_func)(ir_type *tp, ir_mode *m); -/** A function called to set the size of a type in bits */ -typedef void (*set_type_size_func)(ir_type *tp, int size); +/** A function called to set the size of a type in bytes. */ +typedef void (*set_type_size_func)(ir_type *tp, unsigned size); /** A function called to get the number of compound members */ typedef int (*get_n_members_func)(const ir_type *tp); @@ -62,14 +62,14 @@ typedef void (*insert_entity_func)(ir_type *tp, ir_entity *member); * tp_op operations. */ typedef struct _tp_op_ops { - free_attrs_func free_attrs; /**< called to free the attributes of a type */ - free_entities_func free_entities; /**< called to free the owned entities of a type */ - free_auto_entities_func free_auto_entities; /**< called to free the automatic allocated entities of a type */ - set_type_mode_func set_type_mode; /**< called to set a ir_mode of a type */ - set_type_size_func set_type_size; /**< called to set the bit size of a type */ - get_n_members_func get_n_members; /**< called to return the number of compound members */ - get_member_func get_member; /**< called to get the pos'th compound member */ - get_member_index_func get_member_index; /**< called to get the index of a compound member */ + free_attrs_func free_attrs; /**< Called to free the attributes of a type. */ + free_entities_func free_entities; /**< Called to free the owned entities of a type. */ + free_auto_entities_func free_auto_entities; /**< Called to free the automatic allocated entities of a type. */ + set_type_mode_func set_type_mode; /**< Called to set a ir_mode of a type. */ + set_type_size_func set_type_size; /**< Called to set the byte size of a type. */ + get_n_members_func get_n_members; /**< Called to return the number of compound members. */ + get_member_func get_member; /**< Called to get the pos'th compound member. */ + get_member_index_func get_member_index; /**< Called to get the index of a compound member. */ } tp_op_ops; /** possible flags for a type opcode */ @@ -77,13 +77,13 @@ enum tp_op_flags_t { TP_OP_FLAG_COMPOUND = 1 /**< is a compound type */ }; -/** The type opcode */ +/** The type opcode. */ struct tp_op { - tp_opcode code; /**< the tpop code */ - ident *name; /**< the name of the type opcode */ - size_t attr_size; /**< the attribute size for a type of this opcode */ - unsigned flags; /**< flags for this opcode */ - tp_op_ops ops; /**< tp_op operations */ + tp_opcode code; /**< The tpop code. */ + ident *name; /**< The name of the type opcode. */ + size_t attr_size; /**< The attribute size for a type of this opcode. */ + unsigned flags; /**< Flags for this opcode. */ + tp_op_ops ops; /**< tp_op operations. */ }; /** diff --git a/ir/tr/type.c b/ir/tr/type.c index 1a02978b4..2e14085a0 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -137,8 +137,8 @@ new_type(tp_op *type_op, ir_mode *mode, ident *name, dbg_info *db) { res->name = name; res->visibility = visibility_external_allocated; res->flags = tf_none; - res->size = -1; - res->align = -1; + res->size = 0; + res->align = 0; res->visit = 0; res->link = NULL; res->dbi = db; @@ -245,15 +245,10 @@ const char *get_type_name(const ir_type *tp) { return (get_id_str(tp->name)); } -int (get_type_size_bytes)(const ir_type *tp) { +unsigned (get_type_size_bytes)(const ir_type *tp) { return _get_type_size_bytes(tp); } -int (get_type_size_bits)(const ir_type *tp) { - return _get_type_size_bits(tp); -} - - ir_visibility get_type_visibility(const ir_type *tp) { #if 0 visibility res = visibility_local; @@ -305,7 +300,7 @@ void set_type_visibility(ir_type *tp, ir_visibility v) { } void -set_type_size_bits(ir_type *tp, int size) { +set_type_size_bytes(ir_type *tp, unsigned size) { const tp_op *tpop = get_type_tpop(tp); if (tpop->ops.set_type_size) @@ -314,35 +309,24 @@ set_type_size_bits(ir_type *tp, int size) { assert(0 && "Cannot set size for this type"); } -void -set_type_size_bytes(ir_type *tp, int size) { - set_type_size_bits(tp, 8*size); -} - -int get_type_alignment_bytes(ir_type *tp) { - int align = get_type_alignment_bits(tp); - - return align < 0 ? align : (align + 7) >> 3; -} - -int get_type_alignment_bits(ir_type *tp) { - int align = 8; +unsigned get_type_alignment_bytes(ir_type *tp) { + unsigned align = 1; if (tp->align > 0) return tp->align; /* alignment NOT set calculate it "on demand" */ if (tp->mode) - align = get_mode_size_bits(tp->mode); + align = (get_mode_size_bits(tp->mode) + 7) >> 3; else if (is_Array_type(tp)) - align = get_type_alignment_bits(get_array_element_type(tp)); + align = get_type_alignment_bytes(get_array_element_type(tp)); else if (is_compound_type(tp)) { int i, n = get_compound_n_members(tp); align = 0; for (i = 0; i < n; ++i) { - ir_type *t = get_entity_type(get_compound_member(tp, i)); - int a = get_type_alignment_bits(t); + ir_type *t = get_entity_type(get_compound_member(tp, i)); + unsigned a = get_type_alignment_bytes(t); if (a > align) align = a; @@ -358,24 +342,14 @@ int get_type_alignment_bits(ir_type *tp) { } void -set_type_alignment_bits(ir_type *tp, int align) { +set_type_alignment_bytes(ir_type *tp, unsigned align) { assert(tp && tp->kind == k_type); - assert((align == -1 || (align & (align - 1)) == 0) && "type alignment not power of two"); /* Methods don't have an alignment. */ if (tp->type_op != type_method) { tp->align = align; } } -void -set_type_alignment_bytes(ir_type *tp, int align) { - if (align == -1) { - set_type_alignment_bits(tp, -1); - } else { - set_type_alignment_bits(tp, 8*align); - } -} - /* Returns a human readable string for the enum entry. */ const char *get_type_state_name(ir_type_state s) { #define X(a) case a: return #a; @@ -405,7 +379,6 @@ set_type_state(ir_type *tp, ir_type_state state) { int i; switch (get_type_tpop_code(tp)) { case tpo_class: - assert(get_type_size_bits(tp) > -1); if (tp != get_glob_type()) { int n_mem = get_class_n_members(tp); for (i = 0; i < n_mem; i++) { @@ -418,7 +391,6 @@ set_type_state(ir_type *tp, ir_type_state state) { } break; case tpo_struct: - assert(get_type_size_bits(tp) > -1); for (i = 0; i < get_struct_n_members(tp); i++) { assert(get_entity_offset(get_struct_member(tp, i)) > -1); assert((get_entity_allocation(get_struct_member(tp, i)) == allocation_automatic)); @@ -498,7 +470,7 @@ int equal_type(ir_type *typ1, ir_type *typ2) { (get_type_state(typ1) != get_type_state(typ2))) return 0; if ((get_type_state(typ1) == layout_fixed) && - (get_type_size_bits(typ1) != get_type_size_bits(typ2))) + (get_type_size_bytes(typ1) != get_type_size_bytes(typ2))) return 0; switch (get_type_tpop_code(typ1)) { @@ -746,7 +718,7 @@ int smaller_type(ir_type *st, ir_type *lt) { (get_type_state(let) != layout_fixed)) return 0; if (!smaller_type(set, let) || - get_type_size_bits(set) != get_type_size_bits(let)) + get_type_size_bytes(set) != get_type_size_bytes(let)) return 0; } for(i = 0; i < get_array_n_dimensions(st); i++) { @@ -1072,14 +1044,12 @@ int (is_Class_type)(const ir_type *clss) { void set_class_mode(ir_type *tp, ir_mode *mode) { /* for classes and structs we allow to set a mode if the layout is fixed AND the size matches */ assert(get_type_state(tp) == layout_fixed && - tp->size == get_mode_size_bits(mode) && "mode don't match class layout"); + tp->size == get_mode_size_bytes(mode) && "mode don't match class layout"); tp->mode = mode; } -void set_class_size_bits(ir_type *tp, int size) { - /* argh: we must allow to set negative values as "invalid size" */ - tp->size = (size >= 0) ? (size + 7) & ~7 : size; - assert(tp->size == size && "setting a bit size is NOT allowed for this type"); +void set_class_size(ir_type *tp, unsigned size) { + tp->size = size; } /*----------------------------------------------------------------**/ @@ -1166,14 +1136,12 @@ int (is_Struct_type)(const ir_type *strct) { void set_struct_mode(ir_type *tp, ir_mode *mode) { /* for classes and structs we allow to set a mode if the layout is fixed AND the size matches */ assert(get_type_state(tp) == layout_fixed && - tp->size == get_mode_size_bits(mode) && "mode don't match struct layout"); + tp->size == get_mode_size_bytes(mode) && "mode don't match struct layout"); tp->mode = mode; } -void set_struct_size_bits(ir_type *tp, int size) { - /* argh: we must allow to set negative values as "invalid size" */ - tp->size = (size >= 0) ? (size + 7) & ~7 : size; - assert(tp->size == size && "setting a bit size is NOT allowed for this type"); +void set_struct_size(ir_type *tp, unsigned size) { + tp->size = size; } /*******************************************************************/ @@ -1219,7 +1187,7 @@ ir_type *new_d_type_method(ident *name, int n_param, int n_res, dbg_info *db) { assert((get_mode_size_bytes(mode_P_code) != -1) && "unorthodox modes not implemented"); res = new_type(type_method, mode_P_code, name, db); res->flags |= tf_layout_fixed; - res->size = get_mode_size_bits(mode_P_code); + res->size = get_mode_size_bytes(mode_P_code); res->attr.ma.n_params = n_param; res->attr.ma.params = xcalloc(n_param, sizeof(res->attr.ma.params[0])); res->attr.ma.value_params = NULL; @@ -1564,10 +1532,8 @@ int (is_Union_type)(const ir_type *uni) { return _is_union_type(uni); } -void set_union_size_bits(ir_type *tp, int size) { - /* argh: we must allow to set negative values as "invalid size" */ - tp->size = (size >= 0) ? (size + 7) & ~7 : size; - assert(tp->size == size && "setting a bit size is NOT allowed for this type"); +void set_union_size(ir_type *tp, unsigned size) { + tp->size = size; } /*-----------------------------------------------------------------*/ @@ -1766,7 +1732,7 @@ int (is_Array_type)(const ir_type *array) { return _is_array_type(array); } -void set_array_size_bits(ir_type *tp, int size) { +void set_array_size(ir_type *tp, unsigned size) { /* FIXME: Here we should make some checks with the element type size */ tp->size = size; } @@ -1852,7 +1818,7 @@ void set_enumeration_mode(ir_type *tp, ir_mode *mode) { /* For pointer and enumeration size depends on the mode, but only byte size allowed. */ assert((get_mode_size_bits(mode) & 7) == 0 && "unorthodox modes not implemented"); - tp->size = get_mode_size_bits(mode); + tp->size = get_mode_size_bytes(mode); tp->mode = mode; } @@ -1868,7 +1834,7 @@ ir_type *new_d_type_pointer(ident *name, ir_type *points_to, ir_mode *ptr_mode, res = new_type(type_pointer, ptr_mode, name, db); res->attr.pa.points_to = points_to; assert((get_mode_size_bytes(res->mode) != -1) && "unorthodox modes not implemented"); - res->size = get_mode_size_bits(res->mode); + res->size = get_mode_size_bytes(res->mode); res->flags |= tf_layout_fixed; hook_new_type(res); return res; @@ -1909,7 +1875,7 @@ void set_pointer_mode(ir_type *tp, ir_mode *mode) { /* For pointer and enumeration size depends on the mode, but only byte size allowed. */ assert((get_mode_size_bits(mode) & 7) == 0 && "unorthodox modes not implemented"); - tp->size = get_mode_size_bits(mode); + tp->size = get_mode_size_bytes(mode); tp->mode = mode; } @@ -1934,7 +1900,7 @@ ir_type *find_pointer_type_to_type (ir_type *tp) { /* create a new type primitive */ ir_type *new_d_type_primitive(ident *name, ir_mode *mode, dbg_info *db) { ir_type *res = new_type(type_primitive, mode, name, db); - res->size = get_mode_size_bits(mode); + res->size = get_mode_size_bytes(mode); res->flags |= tf_layout_fixed; res->attr.ba.base_type = NULL; hook_new_type(res); @@ -1955,7 +1921,7 @@ void set_primitive_mode(ir_type *tp, ir_mode *mode) { assert(mode_is_data(mode)); /* For primitive size depends on the mode. */ - tp->size = get_mode_size_bits(mode); + tp->size = get_mode_size_bytes(mode); tp->mode = mode; } @@ -2075,7 +2041,7 @@ ir_type *get_associated_type(const ir_type *tp) { } /* set the type size for the unknown and none ir_type */ -void set_default_size_bits(ir_type *tp, int size) { +void set_default_size(ir_type *tp, unsigned size) { tp->size = size; } @@ -2084,12 +2050,13 @@ void set_default_size_bits(ir_type *tp, int size) { * at the start or the end of a frame type. * The frame type must have already an fixed layout. */ -ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at_start) { +ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment, int at_start) { ir_entity *area; ir_type *tp; ident *name; char buf[32]; - int frame_align, i, offset, frame_size; + unsigned frame_align; + int i, offset, frame_size; static unsigned area_cnt = 0; static ir_type *a_byte = NULL; @@ -2105,7 +2072,7 @@ ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at /* align the size */ frame_align = get_type_alignment_bytes(frame_type); - size = (size + frame_align - 1) & -frame_align; + size = (size + frame_align - 1) & ~(frame_align - 1); tp = new_type_array(mangle_u(get_type_ident(frame_type), name), 1, a_byte); set_array_bounds_int(tp, 0, 0, size); @@ -2125,7 +2092,7 @@ ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at } else { /* calculate offset and new type size */ - offset = (frame_size + alignment - 1) & -alignment; + offset = (frame_size + alignment - 1) & ~(alignment - 1); frame_size = offset + size; } diff --git a/ir/tr/type_t.h b/ir/tr/type_t.h index c959edc13..8aac4ba13 100644 --- a/ir/tr/type_t.h +++ b/ir/tr/type_t.h @@ -217,13 +217,13 @@ struct ir_type { ident *name; /**< The name of the type */ ir_visibility visibility;/**< Visibility of entities of this type. */ unsigned flags; /**< Type flags, a bitmask of enum type_flags. */ - int size; /**< Size of an ir_entity of this type. This is determined + unsigned size; /**< Size of an ir_entity of this type. This is determined when fixing the layout of this class. Size must be - given in bits. */ - int align; /**< Alignment of an ir_entity of this type. This should be + given in bytes. */ + unsigned align; /**< Alignment of an ir_entity of this type. This should be set according to the source language needs. If not set it's calculated automatically by get_type_alignment(). - Alignment must be given in bits. */ + Alignment must be given in bytes. */ ir_mode *mode; /**< The mode for atomic types */ unsigned long visit; /**< visited counter for walks of the type information */ void *link; /**< holds temporary data - like in irnode_t.h */ @@ -279,11 +279,11 @@ void set_pointer_mode(ir_type *tp, ir_mode *mode); void set_primitive_mode(ir_type *tp, ir_mode *mode); void set_enumeration_mode(ir_type *tp, ir_mode *mode); -void set_class_size_bits(ir_type *tp, int bits); -void set_struct_size_bits(ir_type *tp, int bits); -void set_union_size_bits(ir_type *tp, int bits); -void set_array_size_bits(ir_type *tp, int size); -void set_default_size_bits(ir_type *tp, int size); +void set_class_size(ir_type *tp, unsigned bytes); +void set_struct_size(ir_type *tp, unsigned bytes); +void set_union_size(ir_type *tp, unsigned bytes); +void set_array_size(ir_type *tp, unsigned bytes); +void set_default_size(ir_type *tp, unsigned bytes); /** * Initialize the type module. @@ -352,24 +352,12 @@ _set_type_ident(ir_type *tp, ident* id) { tp->name = id; } -static INLINE int -_get_type_size_bits(const ir_type *tp) { +static INLINE unsigned +_get_type_size_bytes(const ir_type *tp) { assert(tp && tp->kind == k_type); return tp->size; } -static INLINE int -_get_type_size_bytes(const ir_type *tp) { - int size = _get_type_size_bits(tp); - if (size < 0) - return -1; - if ((size & 7) != 0) { - assert(0 && "cannot take byte size of this type"); - return -1; - } - return size >> 3; -} - static INLINE ir_type_state _get_type_state(const ir_type *tp) { assert(tp && tp->kind == k_type); @@ -608,7 +596,6 @@ _set_method_calling_convention(ir_type *method, unsigned cc_mask) { #define get_type_mode(tp) _get_type_mode(tp) #define get_type_ident(tp) _get_type_ident(tp) #define set_type_ident(tp, id) _set_type_ident(tp, id) -#define get_type_size_bits(tp) _get_type_size_bits(tp) #define get_type_size_bytes(tp) _get_type_size_bytes(tp) #define get_type_state(tp) _get_type_state(tp) #define get_type_visited(tp) _get_type_visited(tp)