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
>From 6c5b3c5401563ffbdae0ad8a62c59e3ebebe8352 Mon Sep 17 00:00:00 2001
From: marxin <mli...@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  <mli...@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

>From 28b94bac8cb50d28ebd3703bdb3516682696c60a Mon Sep 17 00:00:00 2001
From: marxin <mli...@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  <mli...@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

>From 13b00728f4b3e114fb20da69cc853e97eed3424e Mon Sep 17 00:00:00 2001
From: marxin <mli...@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  <mli...@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

Reply via email to