public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4089] gcn: Add __builtin_gcn_kernarg_ptr
@ 2022-11-16 13:25 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2022-11-16 13:25 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6f83861cc1c4d09425aa6539877bfa50ef90f183

commit r13-4089-g6f83861cc1c4d09425aa6539877bfa50ef90f183
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Wed Nov 16 14:24:01 2022 +0100

    gcn: Add __builtin_gcn_kernarg_ptr
    
    Add __builtin_gcn_kernarg_ptr to avoid using hard-coded register values
    and permit future ABI changes while keeping the API.
    
    gcc/ChangeLog:
    
            * config/gcn/gcn-builtins.def (KERNARG_PTR): Add.
            * config/gcn/gcn.cc (gcn_init_builtin_types): Change siptr_type_node,
            sfptr_type_node and voidptr_type_node from FLAT to ADDR_SPACE_DEFAULT.
            (gcn_expand_builtin_1): Handle GCN_BUILTIN_KERNARG_PTR.
            (gcn_oacc_dim_size): Return in ADDR_SPACE_FLAT.
    
    libgomp/ChangeLog:
    
            * config/gcn/team.c (gomp_gcn_enter_kernel): Use
            __builtin_gcn_kernarg_ptr instead of asm ("s8").
    
    Co-Authored-By: Andrew Stubbs <ams@codesourcery.com>

Diff:
---
 gcc/config/gcn/gcn-builtins.def |  4 ++++
 gcc/config/gcn/gcn.cc           | 24 ++++++++++++++++++++----
 libgomp/config/gcn/team.c       |  2 +-
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/gcc/config/gcn/gcn-builtins.def b/gcc/config/gcn/gcn-builtins.def
index c50777bd3b0..eeeaebf9013 100644
--- a/gcc/config/gcn/gcn-builtins.def
+++ b/gcc/config/gcn/gcn-builtins.def
@@ -158,6 +158,10 @@ DEF_BUILTIN (ACC_SINGLE_COPY_END, -1, "single_copy_end", B_INSN,
 DEF_BUILTIN (ACC_BARRIER, -1, "acc_barrier", B_INSN, _A1 (GCN_BTI_VOID),
 	     gcn_expand_builtin_1)
 
+/* Kernel inputs.  */
+
+DEF_BUILTIN (KERNARG_PTR, -1, "kernarg_ptr", B_INSN, _A1 (GCN_BTI_VOIDPTR),
+	     gcn_expand_builtin_1)
 
 #undef _A1
 #undef _A2
diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
index 5e6f3b8b74b..b3814c2e7c6 100644
--- a/gcc/config/gcn/gcn.cc
+++ b/gcc/config/gcn/gcn.cc
@@ -4058,15 +4058,15 @@ gcn_init_builtin_types (void)
 					  (integer_type_node) */
 					, 64);
   tree tmp = build_distinct_type_copy (intSI_type_node);
-  TYPE_ADDR_SPACE (tmp) = ADDR_SPACE_FLAT;
+  TYPE_ADDR_SPACE (tmp) = ADDR_SPACE_DEFAULT;
   siptr_type_node = build_pointer_type (tmp);
 
   tmp = build_distinct_type_copy (float_type_node);
-  TYPE_ADDR_SPACE (tmp) = ADDR_SPACE_FLAT;
+  TYPE_ADDR_SPACE (tmp) = ADDR_SPACE_DEFAULT;
   sfptr_type_node = build_pointer_type (tmp);
 
   tmp = build_distinct_type_copy (void_type_node);
-  TYPE_ADDR_SPACE (tmp) = ADDR_SPACE_FLAT;
+  TYPE_ADDR_SPACE (tmp) = ADDR_SPACE_DEFAULT;
   voidptr_type_node = build_pointer_type (tmp);
 
   tmp = build_distinct_type_copy (void_type_node);
@@ -4493,6 +4493,20 @@ gcn_expand_builtin_1 (tree exp, rtx target, rtx /*subtarget */ ,
       emit_insn (gen_gcn_wavefront_barrier ());
       return target;
 
+    case GCN_BUILTIN_KERNARG_PTR:
+      {
+	rtx ptr;
+	if (cfun->machine->args.reg[KERNARG_SEGMENT_PTR_ARG] >= 0)
+	   ptr = gen_rtx_REG (DImode,
+			      cfun->machine->args.reg[KERNARG_SEGMENT_PTR_ARG]);
+	else
+	  {
+	    ptr = gen_reg_rtx (DImode);
+	    emit_move_insn (ptr, const0_rtx);
+	  }
+	return ptr;
+      }
+
     default:
       gcc_unreachable ();
     }
@@ -5700,7 +5714,9 @@ gcn_oacc_dim_size (int dim)
 					cfun->machine->args.
 					reg[DISPATCH_PTR_ARG]),
 			   GEN_INT (offset[dim]));
-  return gen_rtx_MEM (SImode, addr);
+  rtx mem = gen_rtx_MEM (SImode, addr);
+  set_mem_addr_space (mem, ADDR_SPACE_SCALAR_FLAT);
+  return mem;
 }
 
 /* Helper function for oacc_dim_pos instruction.
diff --git a/libgomp/config/gcn/team.c b/libgomp/config/gcn/team.c
index 254dd4da234..4fc7b62a098 100644
--- a/libgomp/config/gcn/team.c
+++ b/libgomp/config/gcn/team.c
@@ -60,7 +60,7 @@ gomp_gcn_enter_kernel (void)
       /* Initialize the team arena for optimized memory allocation.
          The arena has been allocated on the host side, and the address
          passed in via the kernargs.  Each team takes a small slice of it.  */
-      register void **kernargs asm("s8");
+      void **kernargs = (void**) __builtin_gcn_kernarg_ptr ();
       void *team_arena = (kernargs[4] + TEAM_ARENA_SIZE*teamid);
       void * __lds *arena_start = (void * __lds *)TEAM_ARENA_START;
       void * __lds *arena_free = (void * __lds *)TEAM_ARENA_FREE;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-16 13:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 13:25 [gcc r13-4089] gcn: Add __builtin_gcn_kernarg_ptr Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).