diff mbox

[nvptx] alloca & stack alignment

Message ID 55D77C7A.3030507@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Aug. 21, 2015, 7:31 p.m. UTC
I've committed this to fix up

1) alloca.  PTX defines but doesn't implement support. and if one passes types 
suitable for a 64-bit ABI ptxas emits errors.  This patch gives a clear error at 
compilation time, rather than an obscure failure later.

2) In an effort to reduce when alloca is implicitly used, I added machinery to 
allow the PTX stack to be realigned.  This is very easy on PTX.

We're still left with a bunch of fails due to needing alloca with 
variably-modified types.  I'll be annotating the testsuite shortly

nathan
diff mbox

Patch

2015-08-21  Nathan Sidwell  <nathan@acm.org>

	* config/nvptx/nvptx.md (allocate_stack): Emit sorry during
	expansion.
	* config/nvptx/nvptx.c (nvptx_declare_function_name): Look at
	crtl->stack_alignment_needed to determine alignment.
	(nvptx_get_drap_rtx): New.
	(TARGET_GET_DRAP_RTX): Override.
	* config/nvptx/nvptx.h (MAX_STACK_ALIGNMENT): Set.

Index: config/nvptx/nvptx.md
===================================================================
--- config/nvptx/nvptx.md	(revision 227059)
+++ config/nvptx/nvptx.md	(working copy)
@@ -1241,6 +1241,12 @@ 
    (match_operand 1 "nvptx_register_operand")]
   ""
 {
+  /* The ptx documentation specifies an alloca intrinsic (for 32 bit
+     only)  but notes it is not implemented.  The assembler emits a
+     confused error message.  Issue a blunt one now instead.  */
+  sorry ("target cannot support alloca.");
+  emit_insn (gen_nop ());
+  DONE;
   if (TARGET_ABI64)
     emit_insn (gen_allocate_stack_di (operands[0], operands[1]));
   else
Index: config/nvptx/nvptx.c
===================================================================
--- config/nvptx/nvptx.c	(revision 227059)
+++ config/nvptx/nvptx.c	(working copy)
@@ -598,9 +598,11 @@  nvptx_declare_function_name (FILE *file,
   sz = get_frame_size ();
   if (sz > 0 || cfun->machine->has_call_with_sc)
     {
+      int alignment = crtl->stack_alignment_needed / BITS_PER_UNIT;
+
       fprintf (file, "\t.reg.u%d %%frame;\n"
-	       "\t.local.align 8 .b8 %%farray[" HOST_WIDE_INT_PRINT_DEC"];\n",
-	       BITS_PER_WORD, sz == 0 ? 1 : sz);
+	       "\t.local.align %d .b8 %%farray[" HOST_WIDE_INT_PRINT_DEC"];\n",
+	       BITS_PER_WORD, alignment, sz == 0 ? 1 : sz);
       fprintf (file, "\tcvta.local.u%d %%frame, %%farray;\n",
 	       BITS_PER_WORD);
     }
@@ -726,6 +728,14 @@  nvptx_function_ok_for_sibcall (tree, tre
   return false;
 }
 
+/* Return Dynamic ReAlignment Pointer RTX.  For PTX there isn't any.  */
+
+static rtx
+nvptx_get_drap_rtx (void)
+{
+  return NULL_RTX;
+}
+
 /* Implement the TARGET_CALL_ARGS hook.  Record information about one
    argument to the next call.  */
 
@@ -2118,6 +2128,8 @@  nvptx_file_end (void)
 #define TARGET_LIBCALL_VALUE nvptx_libcall_value
 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
 #define TARGET_FUNCTION_OK_FOR_SIBCALL nvptx_function_ok_for_sibcall
+#undef TARGET_GET_DRAP_RTX
+#define TARGET_GET_DRAP_RTX nvptx_get_drap_rtx
 #undef TARGET_SPLIT_COMPLEX_ARG
 #define TARGET_SPLIT_COMPLEX_ARG hook_bool_const_tree_true
 #undef TARGET_RETURN_IN_MEMORY
Index: config/nvptx/nvptx.h
===================================================================
--- config/nvptx/nvptx.h	(revision 227059)
+++ config/nvptx/nvptx.h	(working copy)
@@ -52,6 +52,8 @@ 
 #define BIGGEST_ALIGNMENT 64
 #define STRICT_ALIGNMENT 1
 
+#define MAX_STACK_ALIGNMENT (1024 * 8)
+
 /* Copied from elf.h and other places.  We'd otherwise use
    BIGGEST_ALIGNMENT and fail a number of testcases.  */
 #define MAX_OFILE_ALIGNMENT (32768 * 8)