[3/10] Move vector types into tdep (i386/amd64/powerpc/spu)

Ulrich Weigand uweigand@de.ibm.com
Fri Jun 8 23:15:00 GMT 2007


Hello,

gdbtypes.c common code provides a significant number of builtin types
related to vectors.  The only user of these are the register_type
routines on three platforms: i386/amd64, powerpc, and spu.

As even those three do not agree on the format of the vector type that
is to be used, I suggest to remove all vector type support from common
code, and have the platform tdep files handle it completely.

Do to initialization order dependencies (noted e.g. in
http://sourceware.org/ml/gdb-patches/2007-01/msg00481.html)
I've also moved the three platforms to a "lazy initialization"
scheme where they allocate the vector type only on first use
(and cache it in the gdbarch_tdep structure).

Tested on i386-linux, powerpc64-linux, and spu-elf.

Bye,
Ulrich


ChangeLog:

	* gdbtypes.c (builtin_type_v2_double, builtin_type_v4_float, 
	builtin_type_v2_int64, builtin_type_v4_int32, builtin_type_v8_int16,
	builtin_type_v16_int8, builtin_type_v2_float, builtin_type_v2_int32,
	builtin_type_v4_int16, builtin_type_v8_int8, builtin_type_v4sf,
	builtin_type_v4si, builtin_type_v16qi, builtin_type_v8qi, 
	builtin_type_v8hi, builtin_type_v4hi, builtin_type_v2si,
	builtin_type_vec64, builtin_type_vec128): Remove.
	(init_simd_type): Remove.
	(init_vector_type): Make global.
	(build_builtin_type_vec64, build_builtin_type_vec128): Remove.
	(build_gdbtypes): Do not build vector types.
	(_initialize_gdbtypes): Do not swap vector types.
	* gdbtypes.h (builtin_type_v2_double, builtin_type_v4_float, 
	builtin_type_v2_int64, builtin_type_v4_int32, builtin_type_v8_int16,
	builtin_type_v16_int8, builtin_type_v2_float, builtin_type_v2_int32,
	builtin_type_v4_int16, builtin_type_v8_int8, builtin_type_v4sf,
	builtin_type_v4si, builtin_type_v16qi, builtin_type_v8qi, 
	builtin_type_v8hi, builtin_type_v4hi, builtin_type_v2si,
	builtin_type_vec64, builtin_type_vec128): Remove declarations.
	(init_vector_type): Add prototype.

	* i386-tdep.h (struct gdbarch_tdep): Add i386_mmx_type and
	i386_sse_type members.
	(i386_mmx_type, i386_sse_type): Change from variables to functions.
	* i386-tdep.c (i386_mmx_type, i386_sse_type): Remove variables.
	(i386_init_types): Do not build vector types.
	(i386_mmx_type, i386_sse_type): New functions.
	(i386_register_type): Call them instead of using global variables.
	(i386_gdbarch_init): Use XCALLOC to allocate tdep structure.
	* amd64-tdep.c (amd64_register_type): Call i386_sse_type instead
	of using global variable.

	* rs6000-tdep.h (struct gdbarch_tdep): Add ppc_builtin_type_vec64
	and ppc_builtin_type_vec128 members.
	* rs6000-tdep.c (rs6000_builtin_type_vec64): New function.
	(rs6000_builtin_type_vec128): Likewise.
	(rs6000_register_type): Call them instead of using builtin_type_vec64
	and builtin_type_vec128.
	(rs6000_gdbarch_init): Use XCALLOC to allocate tdep structure.

	* spu-tdep.c (struct gdbarch_tdep): New data type.
	(spu_builtin_type_vec128): Remove variable.
	(spu_builtin_type_vec128): New function.
	(spu_register_type): Call it instead of using global variable.
	(spu_gdbarch_init): Allocate tdep structure.
	(spu_init_vector_type): Remove function.
	(_initialize_spu_tdep): Do not call it.


diff -urNp gdb-orig/gdb/amd64-tdep.c gdb-head/gdb/amd64-tdep.c
--- gdb-orig/gdb/amd64-tdep.c	2007-06-08 22:19:40.568015100 +0200
+++ gdb-head/gdb/amd64-tdep.c	2007-06-08 22:19:51.766132165 +0200
@@ -106,7 +106,7 @@ amd64_register_type (struct gdbarch *gdb
   if (regnum >= AMD64_FCTRL_REGNUM && regnum <= AMD64_FCRTL_REGNUM + 7)
     return builtin_type_int32;
   if (regnum >= AMD64_XMM0_REGNUM && regnum <= AMD64_XMM0_REGNUM + 15)
-    return i386_sse_type;
+    return i386_sse_type (gdbarch);
   if (regnum == AMD64_MXCSR_REGNUM)
     return i386_mxcsr_type;
 
diff -urNp gdb-orig/gdb/gdbtypes.c gdb-head/gdb/gdbtypes.c
--- gdb-orig/gdb/gdbtypes.c	2007-06-08 22:17:44.695147523 +0200
+++ gdb-head/gdb/gdbtypes.c	2007-06-08 22:19:51.777130581 +0200
@@ -76,29 +76,6 @@ struct type *builtin_type_int128;
 struct type *builtin_type_uint128;
 struct type *builtin_type_bool;
 
-/* 128 bit long vector types */
-struct type *builtin_type_v2_double;
-struct type *builtin_type_v4_float;
-struct type *builtin_type_v2_int64;
-struct type *builtin_type_v4_int32;
-struct type *builtin_type_v8_int16;
-struct type *builtin_type_v16_int8;
-/* 64 bit long vector types */
-struct type *builtin_type_v2_float;
-struct type *builtin_type_v2_int32;
-struct type *builtin_type_v4_int16;
-struct type *builtin_type_v8_int8;
-
-struct type *builtin_type_v4sf;
-struct type *builtin_type_v4si;
-struct type *builtin_type_v16qi;
-struct type *builtin_type_v8qi;
-struct type *builtin_type_v8hi;
-struct type *builtin_type_v4hi;
-struct type *builtin_type_v2si;
-struct type *builtin_type_vec64;
-struct type *builtin_type_vec128;
-
 /* Floatformat pairs.  */
 const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
   &floatformat_ieee_single_big,
@@ -950,33 +927,7 @@ init_flags_type (char *name, int length)
   return type;
 }
 
-/* Construct and return a type of the form:
-	struct NAME { ELT_TYPE ELT_NAME[N]; }
-   We use these types for SIMD registers.  For example, the type of
-   the SSE registers on the late x86-family processors is:
-	struct __builtin_v4sf { float f[4]; }
-   built by the function call:
-	init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
-   The type returned is a permanent type, allocated using malloc; it
-   doesn't live in any objfile's obstack.  */
-static struct type *
-init_simd_type (char *name,
-		struct type *elt_type,
-		char *elt_name,
-		int n)
-{
-  struct type *simd_type;
-  struct type *array_type;
-  
-  simd_type = init_composite_type (name, TYPE_CODE_STRUCT);
-  array_type = create_array_type (0, elt_type,
-				  create_range_type (0, builtin_type_int,
-						     0, n-1));
-  append_composite_type_field (simd_type, elt_name, array_type);
-  return simd_type;
-}
-
-static struct type *
+struct type *
 init_vector_type (struct type *elt_type, int n)
 {
   struct type *array_type;
@@ -988,66 +939,6 @@ init_vector_type (struct type *elt_type,
   return array_type;
 }
 
-static struct type *
-build_builtin_type_vec64 (void)
-{
-  /* Construct a type for the 64 bit registers.  The type we're
-     building is this: */
-#if 0
-  union __gdb_builtin_type_vec64
-  {
-    int64_t uint64;
-    float v2_float[2];
-    int32_t v2_int32[2];
-    int16_t v4_int16[4];
-    int8_t v8_int8[8];
-  };
-#endif
-
-  struct type *t;
-
-  t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION);
-  append_composite_type_field (t, "uint64", builtin_type_int64);
-  append_composite_type_field (t, "v2_float", builtin_type_v2_float);
-  append_composite_type_field (t, "v2_int32", builtin_type_v2_int32);
-  append_composite_type_field (t, "v4_int16", builtin_type_v4_int16);
-  append_composite_type_field (t, "v8_int8", builtin_type_v8_int8);
-
-  TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
-  TYPE_NAME (t) = "builtin_type_vec64";
-  return t;
-}
-
-static struct type *
-build_builtin_type_vec128 (void)
-{
-  /* Construct a type for the 128 bit registers.  The type we're
-     building is this: */
-#if 0
- union __gdb_builtin_type_vec128 
-  {
-    int128_t uint128;
-    float v4_float[4];
-    int32_t v4_int32[4];
-    int16_t v8_int16[8];
-    int8_t v16_int8[16];
-  };
-#endif
-
-  struct type *t;
-
-  t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION);
-  append_composite_type_field (t, "uint128", builtin_type_int128);
-  append_composite_type_field (t, "v4_float", builtin_type_v4_float);
-  append_composite_type_field (t, "v4_int32", builtin_type_v4_int32);
-  append_composite_type_field (t, "v8_int16", builtin_type_v8_int16);
-  append_composite_type_field (t, "v16_int8", builtin_type_v16_int8);
-
-  TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
-  TYPE_NAME (t) = "builtin_type_vec128";
-  return t;
-}
-
 /* Smash TYPE to be a type of pointers to members of DOMAIN with type
    TO_TYPE.  A member pointer is a wierd thing -- it amounts to a
    typed offset into a struct, e.g. "an int at offset 8".  A MEMBER
@@ -3502,39 +3393,6 @@ Show resolution of opaque struct/class/u
 			   &setlist, &showlist);
   opaque_type_resolution = 1;
 
-  /* Build SIMD types.  */
-  builtin_type_v4sf
-    = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
-  builtin_type_v4si
-    = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
-  builtin_type_v16qi
-    = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16);
-  builtin_type_v8qi
-    = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
-  builtin_type_v8hi
-    = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8);
-  builtin_type_v4hi
-    = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
-  builtin_type_v2si
-    = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
-
-  /* 128 bit vectors.  */
-  builtin_type_v2_double = init_vector_type (builtin_type_double, 2);
-  builtin_type_v4_float = init_vector_type (builtin_type_float, 4);
-  builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2);
-  builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4);
-  builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8);
-  builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16);
-  /* 64 bit vectors.  */
-  builtin_type_v2_float = init_vector_type (builtin_type_float, 2);
-  builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2);
-  builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4);
-  builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8);
-
-  /* Vector types.  */
-  builtin_type_vec64 = build_builtin_type_vec64 ();
-  builtin_type_vec128 = build_builtin_type_vec128 ();
-
   /* Pointer/Address types. */
 
   /* NOTE: on some targets, addresses and pointers are not necessarily
@@ -3809,24 +3667,6 @@ _initialize_gdbtypes (void)
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex);
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex);
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16);
-  DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128);
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
   DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
diff -urNp gdb-orig/gdb/gdbtypes.h gdb-head/gdb/gdbtypes.h
--- gdb-orig/gdb/gdbtypes.h	2007-06-08 22:17:44.742140756 +0200
+++ gdb-head/gdb/gdbtypes.h	2007-06-08 22:19:51.821124247 +0200
@@ -1089,31 +1089,6 @@ extern struct type *builtin_type_uint64;
 extern struct type *builtin_type_int128;
 extern struct type *builtin_type_uint128;
 
-/* SIMD types.  We inherit these names from GCC.  */
-extern struct type *builtin_type_v4sf;
-extern struct type *builtin_type_v4si;
-extern struct type *builtin_type_v16qi;
-extern struct type *builtin_type_v8qi;
-extern struct type *builtin_type_v8hi;
-extern struct type *builtin_type_v4hi;
-extern struct type *builtin_type_v2si;
-
-/* Types for 64 bit vectors. */
-extern struct type *builtin_type_v2_float;
-extern struct type *builtin_type_v2_int32;
-extern struct type *builtin_type_v4_int16;
-extern struct type *builtin_type_v8_int8;
-extern struct type *builtin_type_vec64;
-
-/* Types for 128 bit vectors. */
-extern struct type *builtin_type_v2_double;
-extern struct type *builtin_type_v4_float;
-extern struct type *builtin_type_v2_int64;
-extern struct type *builtin_type_v4_int32;
-extern struct type *builtin_type_v8_int16;
-extern struct type *builtin_type_v16_int8;
-extern struct type *builtin_type_vec128;
-
 /* Explicit floating-point formats.  See "floatformat.h".  */
 extern const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN];
 extern const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN];
@@ -1225,6 +1200,8 @@ extern void append_composite_type_field 
 extern struct type *init_flags_type (char *name, int length);
 extern void append_flags_type_flag (struct type *type, int bitpos, char *name);
 
+extern struct type *init_vector_type (struct type *elt_type, int n);
+
 extern struct type *lookup_reference_type (struct type *);
 
 extern struct type *make_reference_type (struct type *, struct type **);
diff -urNp gdb-orig/gdb/i386-tdep.c gdb-head/gdb/i386-tdep.c
--- gdb-orig/gdb/i386-tdep.c	2007-06-08 22:17:44.752139317 +0200
+++ gdb-head/gdb/i386-tdep.c	2007-06-08 22:20:06.361290635 +0200
@@ -1595,9 +1595,7 @@ i386_return_value (struct gdbarch *gdbar
 /* Type for %eflags.  */
 struct type *i386_eflags_type;
 
-/* Types for the MMX and SSE registers.  */
-struct type *i386_mmx_type;
-struct type *i386_sse_type;
+/* Type for %mxcsr.  */
 struct type *i386_mxcsr_type;
 
 /* Construct types for ISA-specific registers.  */
@@ -1626,52 +1624,6 @@ i386_init_types (void)
   append_flags_type_flag (type, 21, "ID");
   i386_eflags_type = type;
 
-  /* The type we're building is this: */
-#if 0
-  union __gdb_builtin_type_vec64i
-  {
-    int64_t uint64;
-    int32_t v2_int32[2];
-    int16_t v4_int16[4];
-    int8_t v8_int8[8];
-  };
-#endif
-
-  type = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
-  append_composite_type_field (type, "uint64", builtin_type_int64);
-  append_composite_type_field (type, "v2_int32", builtin_type_v2_int32);
-  append_composite_type_field (type, "v4_int16", builtin_type_v4_int16);
-  append_composite_type_field (type, "v8_int8", builtin_type_v8_int8);
-  TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
-  TYPE_NAME (type) = "builtin_type_vec64i";
-  i386_mmx_type = type;
-
-  /* The type we're building is this: */
-#if 0
-  union __gdb_builtin_type_vec128i
-  {
-    int128_t uint128;
-    int64_t v2_int64[2];
-    int32_t v4_int32[4];
-    int16_t v8_int16[8];
-    int8_t v16_int8[16];
-    double v2_double[2];
-    float v4_float[4];
-  };
-#endif
-
-  type = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
-  append_composite_type_field (type, "v4_float", builtin_type_v4_float);
-  append_composite_type_field (type, "v2_double", builtin_type_v2_double);
-  append_composite_type_field (type, "v16_int8", builtin_type_v16_int8);
-  append_composite_type_field (type, "v8_int16", builtin_type_v8_int16);
-  append_composite_type_field (type, "v4_int32", builtin_type_v4_int32);
-  append_composite_type_field (type, "v2_int64", builtin_type_v2_int64);
-  append_composite_type_field (type, "uint128", builtin_type_int128);
-  TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
-  TYPE_NAME (type) = "builtin_type_vec128i";
-  i386_sse_type = type;
-
   type = init_flags_type ("builtin_type_i386_mxcsr", 4);
   append_flags_type_flag (type, 0, "IE");
   append_flags_type_flag (type, 1, "DE");
@@ -1690,6 +1642,90 @@ i386_init_types (void)
   i386_mxcsr_type = type;
 }
 
+/* Construct vector type for MMX registers.  */
+struct type *
+i386_mmx_type (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (!tdep->i386_mmx_type)
+    {
+      /* The type we're building is this: */
+#if 0
+      union __gdb_builtin_type_vec64i
+      {
+        int64_t uint64;
+        int32_t v2_int32[2];
+        int16_t v4_int16[4];
+        int8_t v8_int8[8];
+      };
+#endif
+
+      struct type *t;
+
+      t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
+      append_composite_type_field (t, "uint64", builtin_type_int64);
+      append_composite_type_field (t, "v2_int32",
+				   init_vector_type (builtin_type_int32, 2));
+      append_composite_type_field (t, "v4_int16",
+				   init_vector_type (builtin_type_int16, 4));
+      append_composite_type_field (t, "v8_int8",
+				   init_vector_type (builtin_type_int8, 8));
+
+      TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
+      TYPE_NAME (t) = "builtin_type_vec64i";
+      tdep->i386_mmx_type = t;
+    }
+
+  return tdep->i386_mmx_type;
+}
+
+struct type *
+i386_sse_type (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (!tdep->i386_sse_type)
+    {
+      /* The type we're building is this: */
+#if 0
+      union __gdb_builtin_type_vec128i
+      {
+        int128_t uint128;
+        int64_t v2_int64[2];
+        int32_t v4_int32[4];
+        int16_t v8_int16[8];
+        int8_t v16_int8[16];
+        double v2_double[2];
+        float v4_float[4];
+      };
+#endif
+
+      struct type *t;
+
+      t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION);
+      append_composite_type_field (t, "v4_float",
+				   init_vector_type (builtin_type_float, 4));
+      append_composite_type_field (t, "v2_double",
+				   init_vector_type (builtin_type_double, 2));
+      append_composite_type_field (t, "v16_int8",
+				   init_vector_type (builtin_type_int8, 16));
+      append_composite_type_field (t, "v8_int16",
+				   init_vector_type (builtin_type_int16, 8));
+      append_composite_type_field (t, "v4_int32",
+				   init_vector_type (builtin_type_int32, 4));
+      append_composite_type_field (t, "v2_int64",
+				   init_vector_type (builtin_type_int64, 2));
+      append_composite_type_field (t, "uint128", builtin_type_int128);
+
+      TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
+      TYPE_NAME (t) = "builtin_type_vec128i";
+      tdep->i386_sse_type = t;
+    }
+
+  return tdep->i386_sse_type;
+}
+
 /* Return the GDB type object for the "standard" data type of data in
    register REGNUM.  Perhaps %esi and %edi should go here, but
    potentially they could be used for things other than address.  */
@@ -1710,10 +1746,10 @@ i386_register_type (struct gdbarch *gdba
     return builtin_type_i387_ext;
 
   if (i386_mmx_regnum_p (gdbarch, regnum))
-    return i386_mmx_type;
+    return i386_mmx_type (gdbarch);
 
   if (i386_sse_regnum_p (gdbarch, regnum))
-    return i386_sse_type;
+    return i386_sse_type (gdbarch);
 
 #define I387_ST0_REGNUM I386_ST0_REGNUM
 #define I387_NUM_XMM_REGS (gdbarch_tdep (current_gdbarch)->num_xmm_regs)
@@ -2274,7 +2310,7 @@ i386_gdbarch_init (struct gdbarch_info i
     return arches->gdbarch;
 
   /* Allocate space for the new architecture.  */
-  tdep = XMALLOC (struct gdbarch_tdep);
+  tdep = XCALLOC (1, struct gdbarch_tdep);
   gdbarch = gdbarch_alloc (&info, tdep);
 
   /* General-purpose registers.  */
diff -urNp gdb-orig/gdb/i386-tdep.h gdb-head/gdb/i386-tdep.h
--- gdb-orig/gdb/i386-tdep.h	2007-06-08 22:17:44.793133414 +0200
+++ gdb-head/gdb/i386-tdep.h	2007-06-08 22:19:51.910111434 +0200
@@ -104,6 +104,10 @@ struct gdbarch_tdep
      is deprecated, please use `sc_reg_offset' instead.  */
   int sc_pc_offset;
   int sc_sp_offset;
+
+  /* ISA-specific data types.  */
+  struct type *i386_mmx_type;
+  struct type *i386_sse_type;
 };
 
 /* Floating-point registers.  */
@@ -152,10 +156,11 @@ enum i386_regnum
 
 /* Types for i386-specific registers.  */
 extern struct type *i386_eflags_type;
-extern struct type *i386_mmx_type;
-extern struct type *i386_sse_type;
 extern struct type *i386_mxcsr_type;
 
+extern struct type *i386_mmx_type (struct gdbarch *gdbarch);
+extern struct type *i386_sse_type (struct gdbarch *gdbarch);
+
 /* Segment selectors.  */
 #define I386_SEL_RPL	0x0003  /* Requester's Privilege Level mask.  */
 #define I386_SEL_UPL	0x0003	/* User Privilige Level. */
diff -urNp gdb-orig/gdb/ppc-tdep.h gdb-head/gdb/ppc-tdep.h
--- gdb-orig/gdb/ppc-tdep.h	2007-06-08 22:17:44.822129239 +0200
+++ gdb-head/gdb/ppc-tdep.h	2007-06-08 22:19:51.914110858 +0200
@@ -186,6 +186,10 @@ struct gdbarch_tdep
 
     /* Minimum possible text address.  */
     CORE_ADDR text_segment_base;
+
+    /* ISA-specific types.  */
+    struct type *ppc_builtin_type_vec64;
+    struct type *ppc_builtin_type_vec128;
 };
 
 
diff -urNp gdb-orig/gdb/rs6000-tdep.c gdb-head/gdb/rs6000-tdep.c
--- gdb-orig/gdb/rs6000-tdep.c	2007-06-08 22:17:44.832127800 +0200
+++ gdb-head/gdb/rs6000-tdep.c	2007-06-08 22:20:06.373288907 +0200
@@ -2023,6 +2023,88 @@ rs6000_skip_trampoline_code (CORE_ADDR p
   return pc;
 }
 
+/* ISA-specific vector types.  */
+
+static struct type *
+rs6000_builtin_type_vec64 (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (!tdep->ppc_builtin_type_vec64)
+    {
+      /* The type we're building is this: */
+#if 0
+      union __gdb_builtin_type_vec64
+	{
+	  int64_t uint64;
+	  float v2_float[2];
+	  int32_t v2_int32[2];
+	  int16_t v4_int16[4];
+	  int8_t v8_int8[8];
+	};
+#endif
+
+      struct type *t;
+
+      t = init_composite_type ("__ppc_builtin_type_vec64", TYPE_CODE_UNION);
+      append_composite_type_field (t, "uint64", builtin_type_int64);
+      append_composite_type_field (t, "v2_float",
+				   init_vector_type (builtin_type_float, 2));
+      append_composite_type_field (t, "v2_int32",
+				   init_vector_type (builtin_type_int32, 2));
+      append_composite_type_field (t, "v4_int16",
+				   init_vector_type (builtin_type_int16, 4));
+      append_composite_type_field (t, "v8_int8",
+				   init_vector_type (builtin_type_int8, 8));
+
+      TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
+      TYPE_NAME (t) = "ppc_builtin_type_vec64";
+      tdep->ppc_builtin_type_vec64 = t;
+    }
+
+  return tdep->ppc_builtin_type_vec64;
+}
+
+static struct type *
+rs6000_builtin_type_vec128 (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (!tdep->ppc_builtin_type_vec128)
+    {
+      /* The type we're building is this: */
+#if 0
+      union __gdb_builtin_type_vec128
+	{
+	  int128_t uint128;
+	  float v4_float[4];
+	  int32_t v4_int32[4];
+	  int16_t v8_int16[8];
+	  int8_t v16_int8[16];
+	};
+#endif
+
+      struct type *t;
+
+      t = init_composite_type ("__ppc_builtin_type_vec128", TYPE_CODE_UNION);
+      append_composite_type_field (t, "uint128", builtin_type_int128);
+      append_composite_type_field (t, "v4_float",
+				   init_vector_type (builtin_type_float, 4));
+      append_composite_type_field (t, "v4_int32",
+				   init_vector_type (builtin_type_int32, 4));
+      append_composite_type_field (t, "v8_int16",
+				   init_vector_type (builtin_type_int16, 8));
+      append_composite_type_field (t, "v16_int8",
+				   init_vector_type (builtin_type_int8, 16));
+
+      TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
+      TYPE_NAME (t) = "ppc_builtin_type_vec128";
+      tdep->ppc_builtin_type_vec128 = t;
+    }
+
+  return tdep->ppc_builtin_type_vec128;
+}
+
 /* Return the size of register REG when words are WORDSIZE bytes long.  If REG
    isn't available with that word size, return 0.  */
 
@@ -2068,12 +2150,12 @@ rs6000_register_type (struct gdbarch *gd
 	  return builtin_type_uint32;
 	case 8:
 	  if (tdep->ppc_ev0_regnum <= n && n <= tdep->ppc_ev31_regnum)
-	    return builtin_type_vec64;
+	    return rs6000_builtin_type_vec64 (gdbarch);
 	  else
 	    return builtin_type_uint64;
 	  break;
 	case 16:
-	  return builtin_type_vec128;
+	  return rs6000_builtin_type_vec128 (gdbarch);
 	  break;
 	default:
 	  internal_error (__FILE__, __LINE__, _("Register %d size %d unknown"),
@@ -3363,7 +3445,7 @@ rs6000_gdbarch_init (struct gdbarch_info
       info.bfd_arch_info = bfd_get_arch_info (&abfd);
       mach = info.bfd_arch_info->mach;
     }
-  tdep = xmalloc (sizeof (struct gdbarch_tdep));
+  tdep = XCALLOC (1, struct gdbarch_tdep);
   tdep->wordsize = wordsize;
 
   /* For e500 executables, the apuinfo section is of help here.  Such
diff -urNp gdb-orig/gdb/spu-tdep.c gdb-head/gdb/spu-tdep.c
--- gdb-orig/gdb/spu-tdep.c	2007-06-08 22:17:44.892119162 +0200
+++ gdb-head/gdb/spu-tdep.c	2007-06-08 22:19:51.968103084 +0200
@@ -46,8 +46,49 @@
 
 #include "spu-tdep.h"
 
+
+/* The tdep structure.  */
+struct gdbarch_tdep
+{
+  /* SPU-specific vector type.  */
+  struct type *spu_builtin_type_vec128;
+};
+
+
 /* SPU-specific vector type.  */
-struct type *spu_builtin_type_vec128;
+static struct type *
+spu_builtin_type_vec128 (struct gdbarch *gdbarch)
+{
+  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  if (!tdep->spu_builtin_type_vec128)
+    {
+      struct type *t;
+
+      t = init_composite_type ("__spu_builtin_type_vec128", TYPE_CODE_UNION);
+      append_composite_type_field (t, "uint128", builtin_type_int128);
+      append_composite_type_field (t, "v2_int64",
+				   init_vector_type (builtin_type_int64, 2));
+      append_composite_type_field (t, "v4_int32",
+				   init_vector_type (builtin_type_int32, 4));
+      append_composite_type_field (t, "v8_int16",
+				   init_vector_type (builtin_type_int16, 8));
+      append_composite_type_field (t, "v16_int8",
+				   init_vector_type (builtin_type_int8, 16));
+      append_composite_type_field (t, "v2_double",
+				   init_vector_type (builtin_type_double, 2));
+      append_composite_type_field (t, "v4_float",
+				   init_vector_type (builtin_type_float, 4));
+
+      TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR;
+      TYPE_NAME (t) = "spu_builtin_type_vec128";
+
+      tdep->spu_builtin_type_vec128 = t;
+    }
+
+  return tdep->spu_builtin_type_vec128;
+}
+
 
 /* Registers.  */
 
@@ -87,7 +128,7 @@ static struct type *
 spu_register_type (struct gdbarch *gdbarch, int reg_nr)
 {
   if (reg_nr < SPU_NUM_GPRS)
-    return spu_builtin_type_vec128;
+    return spu_builtin_type_vec128 (gdbarch);
 
   switch (reg_nr)
     {
@@ -1324,6 +1365,7 @@ static struct gdbarch *
 spu_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 {
   struct gdbarch *gdbarch;
+  struct gdbarch_tdep *tdep;
 
   /* Find a candidate among the list of pre-declared architectures.  */
   arches = gdbarch_list_lookup_by_info (arches, &info);
@@ -1335,7 +1377,8 @@ spu_gdbarch_init (struct gdbarch_info in
     return NULL;
 
   /* Yes, create a new architecture.  */
-  gdbarch = gdbarch_alloc (&info, NULL);
+  tdep = XCALLOC (1, struct gdbarch_tdep);
+  gdbarch = gdbarch_alloc (&info, tdep);
 
   /* Disassembler.  */
   set_gdbarch_print_insn (gdbarch, print_insn_spu);
@@ -1399,34 +1442,11 @@ spu_gdbarch_init (struct gdbarch_info in
   return gdbarch;
 }
 
-/* Implement a SPU-specific vector type as replacement
-   for __gdb_builtin_type_vec128.  */
-static void
-spu_init_vector_type (void)
-{
-  struct type *type;
-
-  type = init_composite_type ("__spu_builtin_type_vec128", TYPE_CODE_UNION);
-  append_composite_type_field (type, "uint128", builtin_type_int128);
-  append_composite_type_field (type, "v2_int64", builtin_type_v2_int64);
-  append_composite_type_field (type, "v4_int32", builtin_type_v4_int32);
-  append_composite_type_field (type, "v8_int16", builtin_type_v8_int16);
-  append_composite_type_field (type, "v16_int8", builtin_type_v16_int8);
-  append_composite_type_field (type, "v2_double", builtin_type_v2_double);
-  append_composite_type_field (type, "v4_float", builtin_type_v4_float);
-
-  TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
-  TYPE_NAME (type) = "spu_builtin_type_vec128";
-  spu_builtin_type_vec128 = type;
-}
-
 void
 _initialize_spu_tdep (void)
 {
   register_gdbarch_init (bfd_arch_spu, spu_gdbarch_init);
 
-  spu_init_vector_type ();
-
   /* Add ourselves to objfile event chain.  */
   observer_attach_new_objfile (spu_overlay_new_objfile);
   spu_overlay_data = register_objfile_data ();
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com



More information about the Gdb-patches mailing list