From 6f83861cc1c4d09425aa6539877bfa50ef90f183 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Wed, 16 Nov 2022 14:24:01 +0100 Subject: 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 --- gcc/config/gcn/gcn-builtins.def | 4 ++++ gcc/config/gcn/gcn.cc | 24 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'gcc/config/gcn') diff --git a/gcc/config/gcn/gcn-builtins.def b/gcc/config/gcn/gcn-builtins.def index c50777bd..eeeaebf 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 5e6f3b8..b3814c2 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. -- cgit v1.1