diff mbox

[PTX]

Message ID 56658F55.2050406@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Dec. 7, 2015, 1:53 p.m. UTC
Alex pointed me at his ptx patch 
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03393.html but meanwhile I'd 
reorganized that part of the PTX backend.

This patch implements Alex's patch in the new code base.  There are some minor 
additions.
1) we also look inside vector types.
2) we only limit to Pmode, if the type's mode is BLKmode.  Those are the structs 
where we can't tell whether a pointer initialization will happen.

I think there's still some cleanup on the init emission -- now the object size 
is alwasy a multiple  of the element size, we don't have to deal with any 
trailing partial elements.


nathan
diff mbox

Patch

2015-12-07  Nathan Sidwell  <nathan@acm.org>

	gcc/
	* config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Look inside
	complex and vector types.  Cope with packed structs.

	gcc/testsuite/
	* gcc.target/nvptx/decl-init.c: New.

Index: config/nvptx/nvptx.c
===================================================================
--- config/nvptx/nvptx.c	(revision 231361)
+++ config/nvptx/nvptx.c	(working copy)
@@ -1643,17 +1644,24 @@  nvptx_assemble_decl_begin (FILE *file, c
   while (TREE_CODE (type) == ARRAY_TYPE)
     type = TREE_TYPE (type);
 
-  if (!INTEGRAL_TYPE_P (type) && !SCALAR_FLOAT_TYPE_P (type))
-    type = ptr_type_node;
+  if (TREE_CODE (type) == VECTOR_TYPE
+      || TREE_CODE (type) == COMPLEX_TYPE)
+    /* Neither vector nor complex types can contain the other.  */
+    type = TREE_TYPE (type);
+
   unsigned elt_size = int_size_in_bytes (type);
-  if (elt_size > UNITS_PER_WORD)
-    {
-      type = ptr_type_node;
-      elt_size = int_size_in_bytes (type);
-    }
+
+  /* Largest mode we're prepared to accept.  For BLKmode types we
+     don't know if it'll contain pointer constants, so have to choose
+     pointer size, otherwise we can choose DImode.  */
+  machine_mode elt_mode = TYPE_MODE (type) == BLKmode ? Pmode : DImode;
+
+  elt_size |= GET_MODE_SIZE (elt_mode);
+  elt_size &= -elt_size; /* Extract LSB set.  */
+  elt_mode = mode_for_size (elt_size * BITS_PER_UNIT, MODE_INT, 0);
 
   decl_chunk_size = elt_size;
-  decl_chunk_mode = int_mode_for_mode (TYPE_MODE (type));
+  decl_chunk_mode = elt_mode;
   decl_offset = 0;
   init_part = 0;
 
Index: testsuite/gcc.target/nvptx/decl-init.c
===================================================================
--- testsuite/gcc.target/nvptx/decl-init.c	(revision 0)
+++ testsuite/gcc.target/nvptx/decl-init.c	(working copy)
@@ -0,0 +1,37 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-Wno-long-long" } */
+
+__extension__ _Complex float cf = 1.0f + 2.0if;
+__extension__ _Complex double cd = 3.0 + 4.0i;
+
+long long la[2] = 
+  {0x0102030405060708ll,
+   0x1112131415161718ll};
+
+struct six 
+{
+  char a;
+  short b, c;
+};
+
+struct six six1 = {1, 2, 3};
+struct six six2[2] = {{4, 5, 6}, {7, 8, 9}};
+
+struct __attribute__((packed)) five 
+{
+  char a;
+  int b;
+};
+struct five five1 = {10, 11};
+struct five five2[2] = {{12, 13}, {14, 15}};
+
+int  __attribute__((vector_size(16))) vi = {16, 17, 18, 19};
+
+/* dg-final { scan-assembler ".align 4 .u32 cf\\\[2\\\] = { 1065353216, 1073741824 };" } } */
+/* dg-final { scan-assembler ".align 8 .u64 df\\\[2\\\] = { 4613937818241073152, 4616189618054758400 };" } } */
+/* dg-final { scan-assembler ".align 8 .u64 la\\\[2\\\] = { 72623859790382856, 1230066625199609624 };" } } */
+/* dg-final { scan-assembler ".align 2 .u16 six1\\\[3\\\] = { 1, 2, 3 };" } } */
+/* dg-final { scan-assembler ".align 2 .u16 six2\\\[6\\\] = { 4, 5, 6, 7, 8, 9 };" } } */
+/* dg-final { scan-assembler ".align 1 .u8 five1\\\[5\\\] = { 10, 11, 0, 0, 0 };" } } */
+/* dg-final { scan-assembler ".align 1 .u8 five2\\\[10\\\] = { 12, 13, 0, 0, 0, 14, 15, 0, 0, 0 };" } } */
+/* dg-final { scan-assembler ".align 8 .u32 vi\\\[4\\\] = { 16, 17, 18, 19 };" } } */