[Committed] Remove "magic" numbers in stor-layout.c
Roger Sayle
roger@eyesopen.com
Wed Mar 29 22:41:00 GMT 2006
The following patch removes two instances of the magic number 1000
from stor-layout.c. In both cases this value is used to denote
the maximum possible size of a type (in bits and bytes). With
increasing vector size, this restriction is likely to bite someone
sooner or later, and removing it allows GCC to describe the 8
V64DF registers of the Cray-1 (which were 4096 bytes each :-).
Significantly, in both cases there's actually no reason to use an
arbitrary limit, and the code can easily be rewritten to avoid
imposing constraints on the middle or back-ends.
Admission: When I first encountered the line that set the
TYPE_MAX_VALUE of sizetype to be 1000, I suspected that this
bizarre behaviour may have been responsible from my Ada vs.
TYPE_MAX_VALUE woes. Using a more sensible default should
avoid possible confusion in future.
The following patch was tested on i686-pc-linux-gnu with a full
"make bootstrap", including Ada, and regression tested with a
top-level "make -k check" with no new failures.
Committed to mainline as revision 112513.
2006-03-29 Roger Sayle <roger@eyesopen.com>
* stor-layout.c (mode_for_size_tree): Remove restiction on type
sizes by correctly testing whether the size fits a host integer.
(initialize_sizetypes): Use set_min_and_max_values_for_integral_type
to correctly set TYPE_MIN_VALUE and TYPE_MAX_VALUE to the full
SImode range for the default sizetype and bitsizetype.
Index: stor-layout.c
===================================================================
*** stor-layout.c (revision 112438)
--- stor-layout.c (working copy)
*************** mode_for_size (unsigned int size, enum m
*** 190,204 ****
enum machine_mode
mode_for_size_tree (tree size, enum mode_class class, int limit)
{
! if (TREE_CODE (size) != INTEGER_CST
! || TREE_OVERFLOW (size)
! /* What we really want to say here is that the size can fit in a
! host integer, but we know there's no way we'd find a mode for
! this many bits, so there's no point in doing the precise test. */
! || compare_tree_int (size, 1000) > 0)
return BLKmode;
! else
! return mode_for_size (tree_low_cst (size, 1), class, limit);
}
/* Similar, but never return BLKmode; return the narrowest mode that
--- 190,205 ----
enum machine_mode
mode_for_size_tree (tree size, enum mode_class class, int limit)
{
! unsigned HOST_WIDE_INT uhwi;
! unsigned int ui;
!
! if (!host_integerp (size, 1))
return BLKmode;
! uhwi = tree_low_cst (size, 1);
! ui = uhwi;
! if (uhwi != ui)
! return BLKmode;
! return mode_for_size (ui, class, limit);
}
/* Similar, but never return BLKmode; return the narrowest mode that
*************** void
*** 1938,1957 ****
initialize_sizetypes (bool signed_p)
{
tree t = make_node (INTEGER_TYPE);
TYPE_MODE (t) = SImode;
TYPE_ALIGN (t) = GET_MODE_ALIGNMENT (SImode);
TYPE_USER_ALIGN (t) = 0;
TYPE_IS_SIZETYPE (t) = 1;
TYPE_UNSIGNED (t) = !signed_p;
! TYPE_SIZE (t) = build_int_cst (t, GET_MODE_BITSIZE (SImode));
TYPE_SIZE_UNIT (t) = build_int_cst (t, GET_MODE_SIZE (SImode));
! TYPE_PRECISION (t) = GET_MODE_BITSIZE (SImode);
! TYPE_MIN_VALUE (t) = build_int_cst (t, 0);
! /* 1000 avoids problems with possible overflow and is certainly
! larger than any size value we'd want to be storing. */
! TYPE_MAX_VALUE (t) = build_int_cst (t, 1000);
sizetype = t;
bitsizetype = build_distinct_type_copy (t);
--- 1939,1957 ----
initialize_sizetypes (bool signed_p)
{
tree t = make_node (INTEGER_TYPE);
+ int precision = GET_MODE_BITSIZE (SImode);
TYPE_MODE (t) = SImode;
TYPE_ALIGN (t) = GET_MODE_ALIGNMENT (SImode);
TYPE_USER_ALIGN (t) = 0;
TYPE_IS_SIZETYPE (t) = 1;
TYPE_UNSIGNED (t) = !signed_p;
! TYPE_SIZE (t) = build_int_cst (t, precision);
TYPE_SIZE_UNIT (t) = build_int_cst (t, GET_MODE_SIZE (SImode));
! TYPE_PRECISION (t) = precision;
! /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE. */
! set_min_and_max_values_for_integral_type (t, precision, !signed_p);
sizetype = t;
bitsizetype = build_distinct_type_copy (t);
Roger
--
More information about the Gcc-patches
mailing list