From 72c602fc0105c277205ef0009ced55cf1aac1b11 Mon Sep 17 00:00:00 2001 From: Richard Kenner Date: Sat, 4 Mar 2000 16:40:05 +0000 Subject: [PATCH] machmode.h (mode_for_size, [...]): SIZE now signed. * machmode.h (mode_for_size, smallest_mode_for_size): SIZE now signed. * stor-layout.c (mode_for_size, smallest_mode_for_size): Likewise. (mode_for_size_tree): New function. (layout_decl, layout_type): Call it and clean up BLKmode checks. * tree.h (mode_for_size_tree): New declaration. From-SVN: r32326 --- gcc/ChangeLog | 6 +++++ gcc/machmode.h | 9 ++++--- gcc/stor-layout.c | 64 ++++++++++++++++++++++++++++++----------------- gcc/tree.h | 8 ++++++ 4 files changed, 60 insertions(+), 27 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dab8a838758..e53307dca94 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ Sat Mar 4 11:32:30 2000 Richard Kenner + * machmode.h (mode_for_size, smallest_mode_for_size): SIZE now signed. + * stor-layout.c (mode_for_size, smallest_mode_for_size): Likewise. + (mode_for_size_tree): New function. + (layout_decl, layout_type): Call it and clean up BLKmode checks. + * tree.h (mode_for_size_tree): New declaration. + * toplev.c (debug_ignore_block): Mark arg BLOCK as possibly unused. 2000-03-04 Jason Merrill diff --git a/gcc/machmode.h b/gcc/machmode.h index 702e20967a6..fd2101bcf51 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -1,5 +1,6 @@ /* Machine mode definitions for GNU C-Compiler; included by rtl.h and tree.h. - Copyright (C) 1991, 93, 94, 96, 98, 99, 2000 Free Software Foundation, Inc. + Copyright (C) 1991, 1993, 1994, 1996, 1998, 1999, 2000 + Free Software Foundation, Inc. This file is part of GNU CC. @@ -105,12 +106,12 @@ extern const unsigned char mode_wider_mode[]; If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE. The value is BLKmode if no other mode is found. */ -extern enum machine_mode mode_for_size PARAMS ((unsigned int, enum mode_class, int)); +extern enum machine_mode mode_for_size PARAMS ((int, enum mode_class, int)); /* Similar, but find the smallest mode for a given width. */ -extern enum machine_mode smallest_mode_for_size PARAMS ((unsigned int, - enum mode_class)); +extern enum machine_mode smallest_mode_for_size + PARAMS ((int, enum mode_class)); /* Return an integer mode of the exact same size as the input mode, diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index ab925694e31..3aa186cf9f7 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -150,30 +150,52 @@ variable_size (size) enum machine_mode mode_for_size (size, class, limit) - unsigned int size; + int size; enum mode_class class; int limit; { register enum machine_mode mode; - if (limit && size > (unsigned int)(MAX_FIXED_MODE_SIZE)) + if (limit && size > MAX_FIXED_MODE_SIZE) return BLKmode; /* Get the first mode which has this size, in the specified class. */ for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode)) - if ((unsigned int)GET_MODE_BITSIZE (mode) == size) + if (GET_MODE_BITSIZE (mode) == size) return mode; return BLKmode; } +/* Similar, except passed a tree node. */ + +enum machine_mode +mode_for_size_tree (size, class, limit) + tree size; + enum mode_class class; + int limit; +{ + if (TREE_CODE (size) != INTEGER_CST + || TREE_INT_CST_HIGH (size) != 0 + /* If the low-order part is so high as to appear negative, we can't + find a mode for that many bits. */ + || TREE_INT_CST_LOW (size) < 0 + /* 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. */ + || TREE_INT_CST_LOW (size) > 1000) + return BLKmode; + else + return mode_for_size (TREE_INT_CST_LOW (size), class, limit); +} + /* Similar, but never return BLKmode; return the narrowest mode that contains at least the requested number of bits. */ enum machine_mode smallest_mode_for_size (size, class) - unsigned int size; + int size; enum mode_class class; { register enum machine_mode mode; @@ -182,7 +204,7 @@ smallest_mode_for_size (size, class) specified class. */ for (mode = GET_CLASS_NARROWEST_MODE (class); mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode)) - if ((unsigned int)GET_MODE_BITSIZE (mode) >= size) + if (GET_MODE_BITSIZE (mode) >= size) return mode; abort (); @@ -332,7 +354,7 @@ layout_decl (decl, known_align) && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT) { register enum machine_mode xmode - = mode_for_size (TREE_INT_CST_LOW (DECL_SIZE (decl)), MODE_INT, 1); + = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1); if (xmode != BLKmode && known_align % GET_MODE_ALIGNMENT (xmode) == 0) @@ -1058,19 +1080,17 @@ layout_type (type) TYPE_MODE (type) = BLKmode; if (TYPE_SIZE (type) != 0 - && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST /* BLKmode elements force BLKmode aggregate; else extract/store fields may lose. */ && (TYPE_MODE (TREE_TYPE (type)) != BLKmode || TYPE_NO_FORCE_BLK (TREE_TYPE (type)))) { TYPE_MODE (type) - = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)), - MODE_INT, 1); + = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1); - if (STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT - && ((int) TYPE_ALIGN (type) - < TREE_INT_CST_LOW (TYPE_SIZE (type))) + if (TYPE_MODE (type) != BLKmode + && STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT + && TYPE_ALIGN (type) < GET_MODE_ALIGNMENT (TYPE_MODE (type)) && TYPE_MODE (type) != BLKmode) { TYPE_NO_FORCE_BLK (type) = 1; @@ -1136,21 +1156,20 @@ layout_type (type) TYPE_MODE (type) = mode; else TYPE_MODE (type) - = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)), - MODE_INT, 1); + = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1); /* If structure's known alignment is less than what the scalar mode would need, and it matters, then stick with BLKmode. */ - if (STRICT_ALIGNMENT + if (TYPE_MODE (type) != BLKmode + && STRICT_ALIGNMENT && ! (TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT - || ((int) TYPE_ALIGN (type) - >= TREE_INT_CST_LOW (TYPE_SIZE (type))))) + || (TYPE_ALIGN (type) >= + GET_MODE_ALIGNMENT (TYPE_MODE (type))))) { - if (TYPE_MODE (type) != BLKmode) - /* If this is the only reason this type is BLKmode, - then don't force containing types to be BLKmode. */ - TYPE_NO_FORCE_BLK (type) = 1; + /* If this is the only reason this type is BLKmode, + then don't force containing types to be BLKmode. */ + TYPE_NO_FORCE_BLK (type) = 1; TYPE_MODE (type) = BLKmode; } @@ -1195,8 +1214,7 @@ layout_type (type) } TYPE_MODE (type) - = mode_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)), - MODE_INT, 1); + = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1); union_lose: ; } diff --git a/gcc/tree.h b/gcc/tree.h index 4c9fc7311a4..1a827581c6b 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1799,6 +1799,14 @@ extern tree type_hash_canon PARAMS ((int, tree)); extern void layout_decl PARAMS ((tree, unsigned)); +/* Return the mode for data of a given size SIZE and mode class CLASS. + If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE. + The value is BLKmode if no other mode is found. This is like + mode_for_size, but is passed a tree. */ + +extern enum machine_mode mode_for_size_tree PARAMS ((tree, enum mode_class, + int)); + /* Return an expr equal to X but certainly not valid as an lvalue. */ extern tree non_lvalue PARAMS ((tree)); -- 2.30.2