RFA: shrink main_type
Tom Tromey
tromey@redhat.com
Sun Aug 17 18:50:00 GMT 2008
This patch shrinks struct main_type 32- and 64-bit machines by
shrinking the type_code and flags fields and moving around a couple
other fields.
On my x86 box, this saves about 1% of memory on "gdb -readnow cc1" --
a few hundred K -- at the cost of slightly increasing gdb's text size.
I turned the TYPE_FLAG_* defines into an enum to ensure that we'd get
a warning if we ever overflow the 'flags' field.
I noticed that the Ada code does not use TYPE_FLAG_* consistently with
the rest of gdb (it tests the flags directly rather than using the
macros), but I didn't change this.
Built & regtested on x86-64. Ok?
Tom
:ADDPATCH types:
2008-08-17 Tom Tromey <tromey@redhat.com>
* gdbtypes.h (enum type_flag_value): New enum.
(TYPE_FLAG_UNSIGNED, TYPE_FLAG_NOSIGN, TYPE_FLAG_STUB,
TYPE_FLAG_TARGET_STUB, TYPE_FLAG_STATIC, TYPE_FLAG_CONST,
TYPE_FLAG_VOLATILE, TYPE_FLAG_PROTOTYPED, TYPE_FLAG_INCOMPLETE,
TYPE_FLAG_CODE_SPACE, TYPE_FLAG_DATA_SPACE, TYPE_FLAG_VARARGS,
TYPE_FLAG_VECTOR, TYPE_FLAG_ADDRESS_CLASS_1,
TYPE_FLAG_ADDRESS_CLASS_2, TYPE_FLAG_FIXED_INSTANCE,
TYPE_FLAG_STUB_SUPPORTED, TYPE_FLAG_NOTTEXT): Now enum constants.
(struct main_type) <code>: Now 5 bits.
<flags>: Move earlier. Now a bit field.
<nfields, vptr_fieldno>: Move earlier.
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 7ef7d67..5948a8d 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -144,26 +144,47 @@ enum type_code
#define TYPE_CODE_CLASS TYPE_CODE_STRUCT
-/* Some bits for the type's flags word, and macros to test them. */
+/* Some bits for the type's flags word, and macros to test them. See
+ the bit-testing code, below, for documentation of each constant in
+ this enum. */
+
+enum type_flag_value
+{
+ TYPE_FLAG_UNSIGNED = (1 << 0),
+ TYPE_FLAG_NOSIGN = (1 << 1),
+ TYPE_FLAG_STUB = (1 << 2),
+ TYPE_FLAG_TARGET_STUB = (1 << 3),
+ TYPE_FLAG_STATIC = (1 << 4),
+ TYPE_FLAG_CONST = (1 << 5),
+ TYPE_FLAG_VOLATILE = (1 << 6),
+ TYPE_FLAG_PROTOTYPED = (1 << 7),
+ TYPE_FLAG_INCOMPLETE = (1 << 8),
+ TYPE_FLAG_CODE_SPACE = (1 << 9),
+ TYPE_FLAG_DATA_SPACE = (1 << 10),
+ TYPE_FLAG_VARARGS = (1 << 11),
+ TYPE_FLAG_VECTOR = (1 << 12),
+ TYPE_FLAG_ADDRESS_CLASS_1 = (1 << 13),
+ TYPE_FLAG_ADDRESS_CLASS_2 = (1 << 14),
+ TYPE_FLAG_FIXED_INSTANCE = (1 << 15),
+ TYPE_FLAG_STUB_SUPPORTED = (1 << 16),
+ TYPE_FLAG_NOTTEXT = (1 << 17)
+};
/* Unsigned integer type. If this is not set for a TYPE_CODE_INT, the
type is signed (unless TYPE_FLAG_NOSIGN (below) is set). */
-#define TYPE_FLAG_UNSIGNED (1 << 0)
#define TYPE_UNSIGNED(t) (TYPE_FLAGS (t) & TYPE_FLAG_UNSIGNED)
/* No sign for this type. In C++, "char", "signed char", and "unsigned
char" are distinct types; so we need an extra flag to indicate the
absence of a sign! */
-#define TYPE_FLAG_NOSIGN (1 << 1)
#define TYPE_NOSIGN(t) (TYPE_FLAGS (t) & TYPE_FLAG_NOSIGN)
/* This appears in a type's flags word if it is a stub type (e.g., if
someone referenced a type that wasn't defined in a source file
via (struct sir_not_appearing_in_this_film *)). */
-#define TYPE_FLAG_STUB (1 << 2)
#define TYPE_STUB(t) (TYPE_FLAGS (t) & TYPE_FLAG_STUB)
/* The target type of this type is a stub type, and this type needs to
@@ -172,7 +193,6 @@ enum type_code
gets set based on the TYPE_LENGTH of the target type.
Also, set for TYPE_CODE_TYPEDEF. */
-#define TYPE_FLAG_TARGET_STUB (1 << 3)
#define TYPE_TARGET_STUB(t) (TYPE_FLAGS (t) & TYPE_FLAG_TARGET_STUB)
/* Static type. If this is set, the corresponding type had
@@ -181,21 +201,18 @@ enum type_code
* are indicated by other means (bitpos == -1)
*/
-#define TYPE_FLAG_STATIC (1 << 4)
#define TYPE_STATIC(t) (TYPE_FLAGS (t) & TYPE_FLAG_STATIC)
/* Constant type. If this is set, the corresponding type has a
* const modifier.
*/
-#define TYPE_FLAG_CONST (1 << 5)
#define TYPE_CONST(t) (TYPE_INSTANCE_FLAGS (t) & TYPE_FLAG_CONST)
/* Volatile type. If this is set, the corresponding type has a
* volatile modifier.
*/
-#define TYPE_FLAG_VOLATILE (1 << 6)
#define TYPE_VOLATILE(t) (TYPE_INSTANCE_FLAGS (t) & TYPE_FLAG_VOLATILE)
@@ -203,7 +220,6 @@ enum type_code
for function calls in order to tell us if it's necessary to coerce the args,
or to just do the standard conversions. This is used with a short field. */
-#define TYPE_FLAG_PROTOTYPED (1 << 7)
#define TYPE_PROTOTYPED(t) (TYPE_FLAGS (t) & TYPE_FLAG_PROTOTYPED)
/* This flag is used to indicate that processing for this type
@@ -214,7 +230,6 @@ enum type_code
info; the incomplete type has to be marked so that the class and
the method can be assigned correct types.) */
-#define TYPE_FLAG_INCOMPLETE (1 << 8)
#define TYPE_INCOMPLETE(t) (TYPE_FLAGS (t) & TYPE_FLAG_INCOMPLETE)
/* Instruction-space delimited type. This is for Harvard architectures
@@ -236,22 +251,18 @@ enum type_code
If neither flag is set, the default space for functions / methods
is instruction space, and for data objects is data memory. */
-#define TYPE_FLAG_CODE_SPACE (1 << 9)
#define TYPE_CODE_SPACE(t) (TYPE_INSTANCE_FLAGS (t) & TYPE_FLAG_CODE_SPACE)
-#define TYPE_FLAG_DATA_SPACE (1 << 10)
#define TYPE_DATA_SPACE(t) (TYPE_INSTANCE_FLAGS (t) & TYPE_FLAG_DATA_SPACE)
/* FIXME drow/2002-06-03: Only used for methods, but applies as well
to functions. */
-#define TYPE_FLAG_VARARGS (1 << 11)
#define TYPE_VARARGS(t) (TYPE_FLAGS (t) & TYPE_FLAG_VARARGS)
/* Identify a vector type. Gcc is handling this by adding an extra
attribute to the array type. We slurp that in as a new flag of a
type. This is used only in dwarf2read.c. */
-#define TYPE_FLAG_VECTOR (1 << 12)
#define TYPE_VECTOR(t) (TYPE_FLAGS (t) & TYPE_FLAG_VECTOR)
/* Address class flags. Some environments provide for pointers whose
@@ -259,10 +270,8 @@ enum type_code
where the bits are interpreted differently than normal addresses. The
TYPE_FLAG_ADDRESS_CLASS_n flags may be used in target specific
ways to represent these different types of address classes. */
-#define TYPE_FLAG_ADDRESS_CLASS_1 (1 << 13)
#define TYPE_ADDRESS_CLASS_1(t) (TYPE_INSTANCE_FLAGS(t) \
& TYPE_FLAG_ADDRESS_CLASS_1)
-#define TYPE_FLAG_ADDRESS_CLASS_2 (1 << 14)
#define TYPE_ADDRESS_CLASS_2(t) (TYPE_INSTANCE_FLAGS(t) \
& TYPE_FLAG_ADDRESS_CLASS_2)
#define TYPE_FLAG_ADDRESS_CLASS_ALL (TYPE_FLAG_ADDRESS_CLASS_1 \
@@ -279,20 +288,17 @@ enum type_code
the necessary run-time information, and does not need further
interpretation. Optionally marks ordinary, fixed-size GDB type. */
-#define TYPE_FLAG_FIXED_INSTANCE (1 << 15)
/* This debug target supports TYPE_STUB(t). In the unsupported case we have to
rely on NFIELDS to be zero etc., see TYPE_IS_OPAQUE ().
TYPE_STUB(t) with !TYPE_STUB_SUPPORTED(t) may exist if we only guessed
the TYPE_STUB(t) value (see dwarfread.c). */
-#define TYPE_FLAG_STUB_SUPPORTED (1 << 16)
#define TYPE_STUB_SUPPORTED(t) (TYPE_FLAGS (t) & TYPE_FLAG_STUB_SUPPORTED)
/* Not textual. By default, GDB treats all single byte integers as
characters (or elements of strings) unless this flag is set. */
-#define TYPE_FLAG_NOTTEXT (1 << 17)
#define TYPE_NOTTEXT(t) (TYPE_FLAGS (t) & TYPE_FLAG_NOTTEXT)
/* Array bound type. */
@@ -313,7 +319,7 @@ struct main_type
{
/* Code for kind of type */
- ENUM_BITFIELD(type_code) code : 8;
+ ENUM_BITFIELD(type_code) code : 5;
/* Array bounds. These fields appear at this location because
they pack nicely here. */
@@ -321,6 +327,29 @@ struct main_type
ENUM_BITFIELD(array_bound_type) upper_bound_type : 4;
ENUM_BITFIELD(array_bound_type) lower_bound_type : 4;
+ /* Flags about this type. This field appears at this location
+ because it packs nicely here. */
+
+ ENUM_BITFIELD(type_flag_value) flags : 18;
+
+ /* Number of fields described for this type. This field appears at
+ this location because it packs nicely here. */
+
+ short nfields;
+
+ /* Field number of the virtual function table pointer in
+ VPTR_BASETYPE. If -1, we were unable to find the virtual
+ function table pointer in initial symbol reading, and
+ get_vptr_fieldno should be called to find it if possible.
+ get_vptr_fieldno will update this field if possible.
+ Otherwise the value is left at -1.
+
+ Unused if this type does not have virtual functions.
+
+ This field appears at this location because it packs nicely here. */
+
+ short vptr_fieldno;
+
/* Name of this type, or NULL if none.
This is used for printing only, except by poorly designed C++ code.
@@ -364,25 +393,6 @@ struct main_type
struct type *target_type;
- /* Flags about this type. */
-
- int flags;
-
- /* Number of fields described for this type */
-
- short nfields;
-
- /* Field number of the virtual function table pointer in
- VPTR_BASETYPE. If -1, we were unable to find the virtual
- function table pointer in initial symbol reading, and
- get_vptr_fieldno should be called to find it if possible.
- get_vptr_fieldno will update this field if possible.
- Otherwise the value is left at -1.
-
- Unused if this type does not have virtual functions. */
-
- short vptr_fieldno;
-
/* For structure and union types, a description of each field.
For set and pascal array types, there is one "field",
whose type is the domain type of the set or array.
More information about the Gdb-patches
mailing list