public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [hsa] Back-end enhancement
@ 2015-11-24 17:50 Martin Liška
  2015-11-25 10:31 ` Martin Liška
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2015-11-24 17:50 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 270 bytes --]

Hi.

Following small series enhances HSA back-end in following manner:

1) HSA: support alloca builtin
2) HSA: dump alignment of mem and alloca instructions
3) HSA: write back OMP arguments after a kernel dispatch

All patches have been committed to the branch.

Martin

[-- Attachment #2: 0001-HSA-support-alloca-builtin.patch --]
[-- Type: text/x-patch, Size: 7674 bytes --]

From 860520b994f96e3a12d85f4dc8185c502df46942 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 24 Nov 2015 15:48:12 +0100
Subject: [PATCH 1/4] HSA: support alloca builtin

gcc/ChangeLog:

2015-11-24  Martin Liska  <mliska@suse.cz>

	* hsa-brig.c (emit_alloca_insn): New function.
	(emit_insn): Handle hsa_insn_alloca.
	* hsa-gen.c (hsa_init_data_for_cfun):
	Add new pool allocator for hsa_insn_alloca.
	(hsa_deinit_data_for_cfun): Release the pool.
	(hsa_insn_alloca::operator new): New function.
	(hsa_insn_alloca::hsa_insn_alloca): Likewise.
	(gen_hsa_alloca): Likewise.
	(gen_hsa_insns_for_call): Handle __builtin_alloca and
	__builtin_alloca_with_align.
	* hsa.h (is_a_helper ::test): New function.
---
 gcc/hsa-brig.c | 31 +++++++++++++++++++++++
 gcc/hsa-gen.c  | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gcc/hsa.h      | 25 +++++++++++++++++++
 3 files changed, 134 insertions(+)

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index fbb08fb..fd60663 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -1295,6 +1295,35 @@ emit_segment_insn (hsa_insn_seg *seg)
   brig_insn_count++;
 }
 
+/* Emit an HSA alloca instruction and all necessary directives,
+   schedule necessary operands for writing .  */
+
+static void
+emit_alloca_insn (hsa_insn_alloca *alloca)
+{
+  struct BrigInstMem repr;
+  gcc_checking_assert (alloca->operand_count () == 2);
+
+  /* This is necessary because of the erroneous typedef of
+     BrigMemoryModifier8_t which introduces padding which may then contain
+     random stuff (which we do not want so that we can test things don't
+     change).  */
+  memset (&repr, 0, sizeof (repr));
+  repr.base.base.byteCount = htole16 (sizeof (repr));
+  repr.base.base.kind = htole16 (BRIG_KIND_INST_MEM);
+  repr.base.opcode = htole16 (alloca->m_opcode);
+  repr.base.type = htole16 (alloca->m_type);
+  repr.base.operands = htole32 (emit_insn_operands (alloca));
+  repr.segment = BRIG_SEGMENT_PRIVATE;
+  repr.modifier.allBits = 0 ;
+  repr.equivClass = 0;
+  repr.align = alloca->m_align;
+  repr.width = BRIG_WIDTH_NONE;
+  memset (&repr.reserved, 0, sizeof (repr.reserved));
+  brig_code.add (&repr, sizeof (repr));
+  brig_insn_count++;
+}
+
 /* Emit an HSA comparison instruction and all necessary directives,
    schedule necessary operands for writing .  */
 
@@ -1699,6 +1728,8 @@ emit_insn (hsa_insn_basic *insn)
     emit_packed_insn (packed);
   else if (hsa_insn_cvt *cvt = dyn_cast <hsa_insn_cvt *> (insn))
     emit_cvt_insn (cvt);
+  else if (hsa_insn_alloca *alloca = dyn_cast <hsa_insn_alloca *> (insn))
+    emit_alloca_insn (alloca);
   else
     emit_basic_insn (insn);
 }
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index e9c67eb..b39123d 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -144,6 +144,7 @@ static object_allocator<hsa_insn_comment> *hsa_allocp_inst_comment;
 static object_allocator<hsa_insn_queue> *hsa_allocp_inst_queue;
 static object_allocator<hsa_insn_packed> *hsa_allocp_inst_packed;
 static object_allocator<hsa_insn_cvt> *hsa_allocp_inst_cvt;
+static object_allocator<hsa_insn_alloca> *hsa_allocp_inst_alloca;
 static object_allocator<hsa_bb> *hsa_allocp_bb;
 
 /* List of pointers to all instructions that come from an object allocator.  */
@@ -354,6 +355,8 @@ hsa_init_data_for_cfun ()
     = new object_allocator<hsa_insn_packed> ("HSA packed instructions");
   hsa_allocp_inst_cvt
     = new object_allocator<hsa_insn_cvt> ("HSA convert instructions");
+  hsa_allocp_inst_alloca
+    = new object_allocator<hsa_insn_alloca> ("HSA alloca instructions");
   hsa_allocp_bb = new object_allocator<hsa_bb> ("HSA basic blocks");
 }
 
@@ -402,6 +405,7 @@ hsa_deinit_data_for_cfun (void)
   delete hsa_allocp_inst_queue;
   delete hsa_allocp_inst_packed;
   delete hsa_allocp_inst_cvt;
+  delete hsa_allocp_inst_alloca;
   delete hsa_allocp_bb;
   delete hsa_cfun;
 }
@@ -1608,6 +1612,26 @@ hsa_insn_cvt::hsa_insn_cvt (hsa_op_with_type *dest, hsa_op_with_type *src)
 {
 }
 
+/* New operator to allocate alloca from pool alloc.  */
+
+void *
+hsa_insn_alloca::operator new (size_t)
+{
+  return hsa_allocp_inst_alloca->allocate_raw ();
+}
+
+/* Constructor of class representing the alloca in HSAIL.  */
+
+hsa_insn_alloca::hsa_insn_alloca (hsa_op_with_type *dest,
+				  hsa_op_with_type *size, unsigned alignment)
+  : hsa_insn_basic (2, BRIG_OPCODE_ALLOCA, dest->m_type, dest, size),
+  m_align (BRIG_ALIGNMENT_8)
+{
+  gcc_assert (dest->m_type == BRIG_TYPE_U32);
+  if (alignment)
+    m_align = hsa_alignment_encoding (alignment);
+}
+
 /* Append an instruction INSN into the basic block.  */
 
 void
@@ -3562,6 +3586,53 @@ gen_get_team_num (gimple *stmt, hsa_bb *hbb)
   hbb->append_insn (basic);
 }
 
+/* Emit instructions that implement alloca builtin gimple STMT.
+   Instructions are appended to basic block HBB.  */
+
+static void
+gen_hsa_alloca (gcall *call, hsa_bb *hbb)
+{
+  tree lhs = gimple_call_lhs (call);
+  if (lhs == NULL_TREE)
+    return;
+
+  built_in_function fn = DECL_FUNCTION_CODE (gimple_call_fndecl (call));
+
+  gcc_checking_assert (fn == BUILT_IN_ALLOCA
+		       || fn == BUILT_IN_ALLOCA_WITH_ALIGN);
+
+  unsigned bit_alignment = 0;
+
+  if (fn == BUILT_IN_ALLOCA_WITH_ALIGN)
+    {
+      tree alignment_tree = gimple_call_arg (call, 1);
+      if (TREE_CODE (alignment_tree) != INTEGER_CST)
+	{
+	  HSA_SORRY_ATV
+	    (gimple_location (call), "support for HSA does not implement "
+	     "__builtin_alloca_with_align with a non-constant "
+	     "alignment: %E", alignment_tree);
+	}
+
+      bit_alignment = tree_to_uhwi (alignment_tree);
+    }
+
+  tree rhs1 = gimple_call_arg (call, 0);
+  hsa_op_with_type *size = hsa_reg_or_immed_for_gimple_op (rhs1, hbb)
+    ->get_in_type (BRIG_TYPE_U32, hbb);
+  hsa_op_with_type *dest = hsa_cfun->reg_for_gimple_ssa (lhs);
+
+  hsa_op_reg *tmp = new hsa_op_reg
+    (hsa_get_segment_addr_type (BRIG_SEGMENT_PRIVATE));
+  hsa_insn_alloca *a = new hsa_insn_alloca (tmp, size, bit_alignment);
+  hbb->append_insn (a);
+
+  hsa_insn_seg *seg = new hsa_insn_seg
+    (BRIG_OPCODE_STOF, hsa_get_segment_addr_type (BRIG_SEGMENT_FLAT),
+     tmp->m_type, BRIG_SEGMENT_PRIVATE, dest, tmp);
+  hbb->append_insn (seg);
+}
+
 /* Set VALUE to a shadow kernel debug argument and append a new instruction
    to HBB basic block.  */
 
@@ -4333,6 +4404,7 @@ gen_hsa_ternary_atomic_for_builtin (bool ret_orig,
 static void
 gen_hsa_insns_for_call (gimple *stmt, hsa_bb *hbb)
 {
+  gcall *call = as_a <gcall *> (stmt);
   tree lhs = gimple_call_lhs (stmt);
   hsa_op_reg *dest;
 
@@ -4711,6 +4783,12 @@ gen_hsa_insns_for_call (gimple *stmt, hsa_bb *hbb)
 
 	break;
       }
+    case BUILT_IN_ALLOCA:
+    case BUILT_IN_ALLOCA_WITH_ALIGN:
+      {
+	gen_hsa_alloca (call, hbb);
+	break;
+      }
     default:
       {
 	gen_hsa_insns_for_direct_call (stmt, hbb);
diff --git a/gcc/hsa.h b/gcc/hsa.h
index f0c3d80..d697542 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -941,6 +941,31 @@ is_a_helper <hsa_insn_cvt *>::test (hsa_insn_basic *p)
   return (p->m_opcode == BRIG_OPCODE_CVT);
 }
 
+/* HSA alloca instruction.  */
+
+class hsa_insn_alloca: public hsa_insn_basic
+{
+public:
+  hsa_insn_alloca (hsa_op_with_type *dest, hsa_op_with_type *size,
+		   unsigned alignment = 0);
+
+  /* Required alignment of the allocation. */
+  BrigAlignment8_t m_align;
+
+  /* Pool allocator.  */
+  void *operator new (size_t);
+};
+
+/* Report whether or not P is an alloca instruction.  */
+
+template <>
+template <>
+inline bool
+is_a_helper <hsa_insn_alloca *>::test (hsa_insn_basic *p)
+{
+  return (p->m_opcode == BRIG_OPCODE_ALLOCA);
+}
+
 /* Basic block of HSA instructions.  */
 
 class hsa_bb
-- 
2.6.3


[-- Attachment #3: 0002-HSA-dump-alignment-of-mem-and-alloca-instructions.patch --]
[-- Type: text/x-patch, Size: 1974 bytes --]

From 90f566eadff12095b9b85f709aa25adcc8c3414a Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 24 Nov 2015 16:17:44 +0100
Subject: [PATCH 2/4] HSA: dump alignment of mem and alloca instructions

gcc/ChangeLog:

2015-11-24  Martin Liska  <mliska@suse.cz>

	* hsa-dump.c (hsa_byte_alignment): New function.
	(dump_hsa_insn_1): Use the function.
---
 gcc/hsa-dump.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/gcc/hsa-dump.c b/gcc/hsa-dump.c
index 1391f7b..70c71bc 100644
--- a/gcc/hsa-dump.c
+++ b/gcc/hsa-dump.c
@@ -621,6 +621,16 @@ hsa_m_atomicop_name (enum BrigAtomicOperation op)
     }
 }
 
+/* Return byte alignment for given BrigAlignment8_t value.  */
+
+static unsigned
+hsa_byte_alignment (BrigAlignment8_t alignment)
+{
+  gcc_assert (alignment != BRIG_ALIGNMENT_NONE);
+
+  return 1 << (alignment - 1);
+}
+
 /* Dump textual representation of HSA IL register REG to file F.  */
 
 static void
@@ -829,6 +839,8 @@ dump_hsa_insn_1 (FILE *f, hsa_insn_basic *insn, int *indent)
       fprintf (f, "%s", hsa_opcode_name (mem->m_opcode));
       if (addr->m_symbol)
 	fprintf (f, "_%s", hsa_seg_name (addr->m_symbol->m_segment));
+      if (mem->m_align != BRIG_ALIGNMENT_NONE)
+	fprintf (f, "_align(%u)", hsa_byte_alignment (mem->m_align));
       if (mem->m_equiv_class != 0)
 	fprintf (f, "_equiv(%i)", mem->m_equiv_class);
       fprintf (f, "_%s ", hsa_type_name (mem->m_type));
@@ -987,6 +999,16 @@ dump_hsa_insn_1 (FILE *f, hsa_insn_basic *insn, int *indent)
       else
 	gcc_unreachable ();
     }
+  else if (is_a <hsa_insn_alloca *> (insn))
+    {
+      hsa_insn_alloca *alloca = as_a <hsa_insn_alloca *> (insn);
+
+      fprintf (f, "%s_align(%u)_%s ", hsa_opcode_name (insn->m_opcode),
+	       hsa_byte_alignment (alloca->m_align),
+	       hsa_type_name (insn->m_type));
+
+      dump_hsa_operands (f, insn);
+    }
   else
     {
       fprintf (f, "%s_%s ", hsa_opcode_name (insn->m_opcode),
-- 
2.6.3


[-- Attachment #4: 0003-HSA-write-back-OMP-arguments-after-a-kernel-dispatch.patch --]
[-- Type: text/x-patch, Size: 3084 bytes --]

From df55b9103bf00e435984eab7a2cd50a3eaf80ef3 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 24 Nov 2015 16:55:55 +0100
Subject: [PATCH 3/4] HSA: write back OMP arguments after a kernel dispatch

gcc/ChangeLog:

2015-11-24  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c (gen_hsa_insns_for_kernel_call): Copy back OMP
	argument that is copied to a dispatched kernel.
---
 gcc/hsa-gen.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index b39123d..75facec 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -4009,10 +4009,10 @@ gen_hsa_insns_for_kernel_call (hsa_bb *hbb, gcall *call)
 
   tree argument = gimple_call_arg (call, 1);
 
+  hsa_symbol *omp_var_decl = NULL;
   if (TREE_CODE (argument) == ADDR_EXPR)
     {
       /* Emit instructions that copy OMP arguments.  */
-
       tree d = TREE_TYPE (TREE_OPERAND (argument, 0));
       unsigned omp_data_size = tree_to_uhwi (TYPE_SIZE_UNIT (d));
       gcc_checking_assert (omp_data_size > 0);
@@ -4020,12 +4020,12 @@ gen_hsa_insns_for_kernel_call (hsa_bb *hbb, gcall *call)
       if (omp_data_size > hsa_cfun->m_maximum_omp_data_size)
 	hsa_cfun->m_maximum_omp_data_size = omp_data_size;
 
-      hsa_symbol *var_decl = get_symbol_for_decl (TREE_OPERAND (argument, 0));
+      omp_var_decl = get_symbol_for_decl (TREE_OPERAND (argument, 0));
 
-      hbb->append_insn (new hsa_insn_comment ("memory copy instructions"));
+      hbb->append_insn (new hsa_insn_comment ("OMP arg memcpy instructions"));
 
-      hsa_op_address *src_addr = new hsa_op_address (var_decl);
-      gen_hsa_memory_copy (hbb, dst_addr, src_addr, var_decl->m_dim);
+      hsa_op_address *src_addr = new hsa_op_address (omp_var_decl);
+      gen_hsa_memory_copy (hbb, dst_addr, src_addr, omp_var_decl->m_dim);
     }
   else if (integer_zerop (argument))
     {
@@ -4107,6 +4107,8 @@ gen_hsa_insns_for_kernel_call (hsa_bb *hbb, gcall *call)
   basic_block dest = split_edge (e);
   edge false_e = EDGE_SUCC (dest, 0);
 
+  basic_block memcpy_dest = split_edge (false_e);
+
   false_e->flags &= ~EDGE_FALLTHRU;
   false_e->flags |= EDGE_FALSE_VALUE;
 
@@ -4114,6 +4116,7 @@ gen_hsa_insns_for_kernel_call (hsa_bb *hbb, gcall *call)
 
   /* Emit blocking signal waiting instruction.  */
   hsa_bb *new_hbb = hsa_init_new_bb (dest);
+  hsa_bb *memcpy_hbb = hsa_init_new_bb (memcpy_dest);
 
   hbb->append_insn (new hsa_insn_comment ("wait for the signal"));
 
@@ -4137,6 +4140,16 @@ gen_hsa_insns_for_kernel_call (hsa_bb *hbb, gcall *call)
   new_hbb->append_insn (cmp);
   new_hbb->append_insn (new hsa_insn_br (ctrl));
 
+  if (TREE_CODE (argument) == ADDR_EXPR)
+    {
+      /* Emit instructions that copy back OMP arguments to a caller kernel.  */
+      memcpy_hbb->append_insn
+	(new hsa_insn_comment ("OMP arg memcpy back instructions"));
+
+      hsa_op_address *src_addr = new hsa_op_address (omp_var_decl);
+      gen_hsa_memory_copy (memcpy_hbb, src_addr, dst_addr, omp_var_decl->m_dim);
+    }
+
   hsa_cfun->m_kernel_dispatch_count++;
 }
 
-- 
2.6.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [hsa] Back-end enhancement
  2015-11-24 17:50 [hsa] Back-end enhancement Martin Liška
@ 2015-11-25 10:31 ` Martin Liška
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liška @ 2015-11-25 10:31 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

On 11/24/2015 06:22 PM, Martin Liška wrote:
> Hi.
> 
> Following small series enhances HSA back-end in following manner:
> 
> 1) HSA: support alloca builtin
> 2) HSA: dump alignment of mem and alloca instructions
> 3) HSA: write back OMP arguments after a kernel dispatch
> 
> All patches have been committed to the branch.
> 
> Martin
> 

Hello.

There's a small follow-up which fixes an issue related to CMP instructions
and the second part of the patch contains small refactoring related
to hsa_symbol class.

Installed to the branch.
Martin

[-- Attachment #2: 0004-HSA-fix-CMP-instruction-emission.patch --]
[-- Type: text/x-patch, Size: 1860 bytes --]

From 6c5b3c5401563ffbdae0ad8a62c59e3ebebe8352 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 24 Nov 2015 18:14:10 +0100
Subject: [PATCH 4/6] HSA: fix CMP instruction emission

gcc/ChangeLog:

2015-11-24  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c (gen_hsa_cmp_insn_from_gimple): If dest type
	of a CMP instruction is an integer type, use B1 as intermediate
	destination register.
	(hsa_insn_basic::set_output_in_type): Fix case where the type
	of an instruction is equal to the type of an argument.
---
 gcc/hsa-gen.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 75facec..b7e649d 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -2748,11 +2748,18 @@ gen_hsa_cmp_insn_from_gimple (enum tree_code code, tree lhs, tree rhs,
       return;
     }
 
-  hsa_insn_cmp *cmp = new hsa_insn_cmp (compare, dest->m_type);
-  cmp->set_op (0, dest);
+  /* CMP instruction returns e.g. 0xffffffff (for a 32-bit with integer)
+     as a result of comparison.  */
+
+  BrigType16_t dest_type = hsa_type_integer_p (dest->m_type)
+    ? (BrigType16_t) BRIG_TYPE_B1 : dest->m_type;
+
+  hsa_insn_cmp *cmp = new hsa_insn_cmp (compare, dest_type);
   cmp->set_op (1, hsa_reg_or_immed_for_gimple_op (lhs, hbb));
   cmp->set_op (2, hsa_reg_or_immed_for_gimple_op (rhs, hbb));
+
   hbb->append_insn (cmp);
+  cmp->set_output_in_type (dest, 0, hbb);
 }
 
 /* Generate an unary instruction with OPCODE and append it to a basic block
@@ -3424,7 +3431,10 @@ hsa_insn_basic::set_output_in_type (hsa_op_reg *dest, unsigned op_index,
   gcc_checking_assert (op_output_p (op_index));
 
   if (dest->m_type == m_type)
-    set_op (op_index, dest);
+    {
+      set_op (op_index, dest);
+      return;
+    }
 
   hsa_op_reg *tmp = new hsa_op_reg (m_type);
   set_op (op_index, tmp);
-- 
2.6.3


[-- Attachment #3: 0005-HSA-clean-up-hsa_symbol.patch --]
[-- Type: text/x-patch, Size: 5082 bytes --]

From 28b94bac8cb50d28ebd3703bdb3516682696c60a Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 25 Nov 2015 10:45:18 +0100
Subject: [PATCH 5/6] HSA: clean-up hsa_symbol

gcc/ChangeLog:

2015-11-25  Martin Liska  <mliska@suse.cz>

	* hsa-brig.c (emit_directive_variable): Use
	hsa_symbol::m_global_scope_p and hsa_symbol::m_allocation.
	* hsa-gen.c (get_symbol_for_decl): Use new ctor of hsa_symbol.
	(hsa_get_string_cst_symbol): Likewise.
	(emit_hsa_module_variables): Likewise.
	* hsa.h (struct hsa_symbol): Add new member variable.
---
 gcc/hsa-brig.c | 19 ++-----------------
 gcc/hsa-gen.c  | 23 +++++++++++++----------
 gcc/hsa.h      |  6 +++++-
 3 files changed, 20 insertions(+), 28 deletions(-)

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index fd60663..463bf16 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -488,7 +488,6 @@ emit_directive_variable (struct hsa_symbol *symbol)
   struct BrigDirectiveVariable dirvar;
   unsigned name_offset;
   static unsigned res_name_offset;
-  char prefix;
 
   if (symbol->m_directive_offset)
     return symbol->m_directive_offset;
@@ -496,23 +495,9 @@ emit_directive_variable (struct hsa_symbol *symbol)
   memset (&dirvar, 0, sizeof (dirvar));
   dirvar.base.byteCount = htole16 (sizeof (dirvar));
   dirvar.base.kind = htole16 (BRIG_KIND_DIRECTIVE_VARIABLE);
-  dirvar.allocation = BRIG_ALLOCATION_AUTOMATIC;
-
-  /* Readonly variables must have agent allocation.  */
-  if (symbol->m_cst_value)
-    dirvar.allocation = BRIG_ALLOCATION_AGENT;
+  dirvar.allocation = symbol->m_allocation;
 
-  if (symbol->m_decl && is_global_var (symbol->m_decl))
-    {
-      prefix = '&';
-
-      if (!symbol->m_cst_value)
-	dirvar.allocation = BRIG_ALLOCATION_PROGRAM;
-    }
-  else if (symbol->m_global_scope_p)
-    prefix = '&';
-  else
-    prefix = '%';
+  char prefix = symbol->m_global_scope_p ? '&' : '%';
 
   if (symbol->m_decl && TREE_CODE (symbol->m_decl) == RESULT_DECL)
     {
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index b7e649d..485d7c2 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -157,17 +157,20 @@ hsa_symbol::hsa_symbol ()
 : m_decl (NULL_TREE), m_name (NULL), m_name_number (0),
   m_directive_offset (0), m_type (BRIG_TYPE_NONE),
   m_segment (BRIG_SEGMENT_NONE), m_linkage (BRIG_LINKAGE_NONE), m_dim (0),
-  m_cst_value (NULL), m_global_scope_p (false), m_seen_error (false)
+  m_cst_value (NULL), m_global_scope_p (false), m_seen_error (false),
+  m_allocation (BRIG_ALLOCATION_AUTOMATIC)
 {
 }
 
 
 hsa_symbol::hsa_symbol (BrigType16_t type, BrigSegment8_t segment,
-			BrigLinkage8_t linkage)
+			BrigLinkage8_t linkage, bool global_scope_p,
+			BrigAllocation allocation)
 : m_decl (NULL_TREE), m_name (NULL), m_name_number (0),
   m_directive_offset (0), m_type (type), m_segment (segment),
-  m_linkage (linkage), m_dim (0), m_cst_value (NULL), m_global_scope_p (false),
-  m_seen_error (false)
+  m_linkage (linkage), m_dim (0), m_cst_value (NULL),
+  m_global_scope_p (global_scope_p), m_seen_error (false),
+  m_allocation (allocation)
 {
 }
 
@@ -730,7 +733,8 @@ get_symbol_for_decl (tree decl)
       if (is_in_global_vars)
 	{
 	  sym = new hsa_symbol (BRIG_TYPE_NONE, BRIG_SEGMENT_GLOBAL,
-				BRIG_LINKAGE_PROGRAM);
+				BRIG_LINKAGE_PROGRAM, true,
+				BRIG_ALLOCATION_PROGRAM);
 	  hsa_cfun->m_global_symbols.safe_push (sym);
 	}
       else
@@ -807,12 +811,12 @@ hsa_get_string_cst_symbol (tree string_cst)
     return *slot;
 
   hsa_op_immed *cst = new hsa_op_immed (string_cst);
-  hsa_symbol *sym = new hsa_symbol (cst->m_type,
-				    BRIG_SEGMENT_GLOBAL, BRIG_LINKAGE_MODULE);
+  hsa_symbol *sym = new hsa_symbol (cst->m_type, BRIG_SEGMENT_GLOBAL,
+				    BRIG_LINKAGE_MODULE, true,
+				    BRIG_ALLOCATION_AGENT);
   sym->m_cst_value = cst;
   sym->m_dim = TREE_STRING_LENGTH (string_cst);
   sym->m_name_number = hsa_cfun->m_global_symbols.length ();
-  sym->m_global_scope_p = true;
 
   hsa_cfun->m_global_symbols.safe_push (sym);
   hsa_cfun->m_string_constants_map.put (string_cst, sym);
@@ -5525,10 +5529,9 @@ static void
 emit_hsa_module_variables (void)
 {
   hsa_num_threads = new hsa_symbol (BRIG_TYPE_U32, BRIG_SEGMENT_PRIVATE,
-				    BRIG_LINKAGE_MODULE);
+				    BRIG_LINKAGE_MODULE, true);
 
   hsa_num_threads->m_name = "hsa_num_threads";
-  hsa_num_threads->m_global_scope_p = true;
 
   hsa_brig_emit_omp_symbols ();
 }
diff --git a/gcc/hsa.h b/gcc/hsa.h
index d697542..4c5183c 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -59,7 +59,8 @@ struct hsa_symbol
 {
   /* Constructor.  */
   hsa_symbol (BrigType16_t type, BrigSegment8_t segment,
-	      BrigLinkage8_t linkage);
+	      BrigLinkage8_t linkage, bool global_scope_p = false,
+	      BrigAllocation allocation = BRIG_ALLOCATION_AUTOMATIC);
 
   /* Return total size of the symbol.  */
   unsigned HOST_WIDE_INT total_byte_size ();
@@ -110,6 +111,9 @@ struct hsa_symbol
   /* True if an error has been seen for the symbol.  */
   bool m_seen_error;
 
+  /* Symbol allocation.  */
+  BrigAllocation m_allocation;
+
 private:
   /* Default constructor.  */
   hsa_symbol ();
-- 
2.6.3


[-- Attachment #4: 0006-HSA-remove-hsa_symbol-global_var_p-predicate.patch --]
[-- Type: text/x-patch, Size: 2563 bytes --]

From 13b00728f4b3e114fb20da69cc853e97eed3424e Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 25 Nov 2015 11:05:06 +0100
Subject: [PATCH 6/6] HSA: remove hsa_symbol::global_var_p predicate

gcc/ChangeLog:

2015-11-25  Martin Liska  <mliska@suse.cz>

	* hsa-brig.c (emit_directive_variable): Replace the predicate
	with test of linkage.
	* hsa-gen.c (hsa_symbol::global_var_p): Remove.
	(hsa_function_representation::~hsa_function_representation): Replace
	the predicate with test of linkage.
	* hsa.h (struct hsa_symbol): Remove declaration.
---
 gcc/hsa-brig.c | 2 +-
 gcc/hsa-gen.c  | 8 +-------
 gcc/hsa.h      | 4 ----
 3 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/gcc/hsa-brig.c b/gcc/hsa-brig.c
index 463bf16..ca30598 100644
--- a/gcc/hsa-brig.c
+++ b/gcc/hsa-brig.c
@@ -528,7 +528,7 @@ emit_directive_variable (struct hsa_symbol *symbol)
   dirvar.dim.hi = (uint32_t) ((unsigned long long) symbol->m_dim >> 32);
 
   /* Global variables are just declared and linked via HSA runtime.  */
-  if (!symbol->global_var_p ())
+  if (symbol->m_linkage != BRIG_ALLOCATION_PROGRAM)
     dirvar.modifier.allBits |= BRIG_VARIABLE_DEFINITION;
   dirvar.reserved = 0;
 
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 485d7c2..0df1eb6 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -203,12 +203,6 @@ hsa_symbol::fillup_for_decl (tree decl)
     m_seen_error = true;
 }
 
-bool
-hsa_symbol::global_var_p ()
-{
-  return m_decl && is_global_var (m_decl);
-}
-
 /* Constructor of class representing global HSA function/kernel information and
    state.  FNDECL is function declaration, KERNEL_P is true if the function
    is going to become a HSA kernel.  If the function has body, SSA_NAMES_COUNT
@@ -250,7 +244,7 @@ hsa_function_representation::~hsa_function_representation ()
 
   hsa_symbol *sym;
   for (unsigned i = 0; i < m_global_symbols.iterate (i, &sym); i++)
-    if (!sym->global_var_p ())
+    if (sym->m_linkage != BRIG_ALLOCATION_PROGRAM)
       delete sym;
   m_global_symbols.release ();
 
diff --git a/gcc/hsa.h b/gcc/hsa.h
index 4c5183c..dc2202a 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -70,10 +70,6 @@ struct hsa_symbol
      or a variable, local or global.  */
   void fillup_for_decl (tree decl);
 
-  /* Return true if the symbol is a global variable that should be preserved
-     after a function is emitted to BRIG.  */
-  bool global_var_p ();
-
   /* Pointer to the original tree, which is PARM_DECL for input parameters and
      RESULT_DECL for the output parameters.  */
   tree m_decl;
-- 
2.6.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-25 10:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-24 17:50 [hsa] Back-end enhancement Martin Liška
2015-11-25 10:31 ` Martin Liška

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).