public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [HSA] HSA back-end improvement
@ 2015-10-16 13:03 Martin Liška
  0 siblings, 0 replies; only message in thread
From: Martin Liška @ 2015-10-16 13:03 UTC (permalink / raw)
  To: gcc-patches

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

Hello.

Attached patch set applies a bunch of small changes to HSA back-end.
Patches have been installed to hsa branch.

Martin

[-- Attachment #2: 0001-HSA-fix-types-in-switch-to-if-conversion-code.patch --]
[-- Type: text/x-patch, Size: 1733 bytes --]

From 10cf42ce8c0199471271edea80bb0cd717b6f0d1 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Fri, 9 Oct 2015 14:36:31 +0200
Subject: [PATCH 1/8] HSA: fix types in switch to if conversion code

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c (convert_switch_statements): Generate fold_convert
	for situations where index type and label value types are different.
---
 gcc/hsa-gen.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index aa57669..3366e01 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -5048,6 +5048,7 @@ convert_switch_statements ()
 
 	unsigned labels = gimple_switch_num_labels (s);
 	tree index = gimple_switch_index (s);
+	tree index_type = TREE_TYPE (index);
 	tree default_label = gimple_switch_default_label (s);
 	basic_block default_label_bb = label_to_block_fn
 	  (func, CASE_LABEL (default_label));
@@ -5100,17 +5101,24 @@ convert_switch_statements ()
 	    tree low = CASE_LOW (label);
 	    tree high = CASE_HIGH (label);
 
+	    if (!useless_type_conversion_p (TREE_TYPE (low), index_type))
+	      low = fold_convert (index_type, low);
+
 	    gimple_stmt_iterator cond_gsi = gsi_last_bb (cur_bb);
 	    gimple *c = NULL;
 	    if (high)
 	      {
 		tree tmp1 = make_temp_ssa_name (boolean_type_node, NULL,
 						"switch_cond_op1");
+
 		gimple *assign1 = gimple_build_assign (tmp1, LE_EXPR, low,
 						      index);
 
 		tree tmp2 = make_temp_ssa_name (boolean_type_node, NULL,
 						"switch_cond_op2");
+
+		if (!useless_type_conversion_p (TREE_TYPE (high), index_type))
+		  high = fold_convert (index_type, high);
 		gimple *assign2 = gimple_build_assign (tmp2, LE_EXPR, index,
 						      high);
 
-- 
2.6.0


[-- Attachment #3: 0002-HSA-introduce-seen_error-for-hsa_symbol-class.patch --]
[-- Type: text/x-patch, Size: 2226 bytes --]

From b0fee876ca636e1623bc2a0a06d73ed435ff6397 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Fri, 9 Oct 2015 16:27:55 +0200
Subject: [PATCH 2/8] HSA: introduce seen_error for hsa_symbol class.

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c (fillup_sym_for_decl): Add new seen_error guard.
	(get_symbol_for_decl): Mark all functions that use a problematic
	symbol as problematic too.
	* hsa.c (hsa_type_bit_size): Use correct seen_error function.
	* hsa.h (struct hsa_symbol): New member flag.
---
 gcc/hsa-gen.c | 14 +++++++++++++-
 gcc/hsa.c     |  2 +-
 gcc/hsa.h     |  3 +++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 3366e01..892fac2 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -658,6 +658,9 @@ fillup_sym_for_decl (tree decl, struct hsa_symbol *sym)
 {
   sym->decl = decl;
   sym->type = hsa_type_for_tree_type (TREE_TYPE (decl), &sym->dim);
+
+  if (hsa_seen_error ())
+    sym->seen_error = true;
 }
 
 /* Lookup or create the associated hsa_symbol structure with a given VAR_DECL
@@ -680,7 +683,16 @@ get_symbol_for_decl (tree decl)
       slot = hsa_global_variable_symbols->find_slot (&dummy, INSERT);
       gcc_checking_assert (slot);
       if (*slot)
-	return *slot;
+	{
+	  sym = *slot;
+
+	  /* If the symbol is problematic, mark current function also as
+	     problematic.  */
+	  if (sym->seen_error)
+	    hsa_fail_cfun ();
+
+	  return sym;
+	}
       sym = XCNEW (struct hsa_symbol);
       sym->segment = BRIG_SEGMENT_GLOBAL;
       sym->linkage = BRIG_LINKAGE_FUNCTION;
diff --git a/gcc/hsa.c b/gcc/hsa.c
index 1617ec6..ed6a779 100644
--- a/gcc/hsa.c
+++ b/gcc/hsa.c
@@ -404,7 +404,7 @@ hsa_type_bit_size (BrigType16_t t)
       return 128;
 
     default:
-      gcc_assert (seen_error ());
+      gcc_assert (hsa_seen_error ());
       return t;
     }
 }
diff --git a/gcc/hsa.h b/gcc/hsa.h
index c7e3957..e2d5aed 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -86,6 +86,9 @@ struct hsa_symbol
 
   /* Is in global scope.  */
   bool global_scope_p;
+
+  /* True if an error has been seen for the symbol.  */
+  bool seen_error;
 };
 
 /* Abstract class for HSA instruction operands. */
-- 
2.6.0


[-- Attachment #4: 0003-HSA-add-new-warning-and-enhance-host-fallback.patch --]
[-- Type: text/x-patch, Size: 1956 bytes --]

From 9eb195d3b8a967d8843299afcd1a487107db9aa1 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 15 Oct 2015 13:18:04 +0200
Subject: [PATCH 3/8] HSA: add new warning and enhance host fallback.

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c (get_symbol_for_decl): Replace warning with
	HSA_SORRY_ATV.

libgomp/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* target.c (GOMP_target): Add new case where we want to process
	host fallback.
---
 gcc/hsa-gen.c    |  4 ++--
 libgomp/target.c | 14 ++++++++++----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 892fac2..9ec1049 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -708,8 +708,8 @@ get_symbol_for_decl (tree decl)
 	  hsa_cfun->readonly_variables.safe_push (sym);
 	}
       else
-	warning (0, "referring to global symbol %q+D by name from HSA code "
-		 "won't work", decl);
+	HSA_SORRY_ATV (EXPR_LOCATION (decl), "referring to global symbol "
+		       "%q+D by name from HSA code won't work", decl);
     }
   else
     {
diff --git a/libgomp/target.c b/libgomp/target.c
index a555c0f..8697daa 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -1004,12 +1004,18 @@ GOMP_target (int device, void (*fn) (void *), const void *kernel_launch,
       k.host_start = (uintptr_t) fn;
       k.host_end = k.host_start + 1;
       splay_tree_key tgt_fn = splay_tree_lookup (&devicep->mem_map, &k);
-      if (tgt_fn == NULL)
+      gomp_mutex_unlock (&devicep->lock);
+
+      if (tgt_fn == NULL )
 	{
-	  gomp_mutex_unlock (&devicep->lock);
-	  gomp_fatal ("Target function wasn't mapped");
+	  if (devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)
+	    {
+	      run_on_host (fn, hostaddrs);
+	      return;
+	    }
+	  else
+	    gomp_fatal ("Target function wasn't mapped");
 	}
-      gomp_mutex_unlock (&devicep->lock);
 
       fn_addr = (void *) tgt_fn->tgt_offset;
     }
-- 
2.6.0


[-- Attachment #5: 0004-HSA-small-refactoring-in-gen_hsa_insns_for_known_lib.patch --]
[-- Type: text/x-patch, Size: 2125 bytes --]

From a2f26a6c3aee7cc992c553dc237c8f6cafd5eb6e Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 15 Oct 2015 13:46:23 +0200
Subject: [PATCH 4/8] HSA: small refactoring in
 gen_hsa_insns_for_known_library_call.

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c (gen_hsa_insns_for_known_library_call):
	Small refactoring.
---
 gcc/hsa-gen.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 9ec1049..dc4aa62 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -3503,28 +3503,15 @@ gen_hsa_insns_for_known_library_call (gimple *stmt, hsa_bb *hbb,
       hsa_op_immed *imm = new hsa_op_immed (build_zero_cst (TREE_TYPE (lhs)));
 
       hsa_build_append_simple_mov (dest, imm, hbb);
-      return true;
     }
   else if (strcmp (name, "omp_set_num_threads") == 0)
-    {
-      gen_set_num_threads (gimple_call_arg (stmt, 0), hbb, ssa_map);
-      return true;
-    }
+    gen_set_num_threads (gimple_call_arg (stmt, 0), hbb, ssa_map);
   else if (strcmp (name, "omp_get_num_threads") == 0)
-    {
-      query_hsa_grid (stmt, BRIG_OPCODE_GRIDSIZE, 0, hbb, ssa_map);
-      return true;
-    }
+    query_hsa_grid (stmt, BRIG_OPCODE_GRIDSIZE, 0, hbb, ssa_map);
   else if (strcmp (name, "omp_get_num_teams") == 0)
-    {
-      gen_get_num_teams (stmt, hbb, ssa_map);
-      return true;
-    }
+    gen_get_num_teams (stmt, hbb, ssa_map);
   else if (strcmp (name, "omp_get_team_num") == 0)
-    {
-      gen_get_team_num (stmt, hbb, ssa_map);
-      return true;
-    }
+    gen_get_team_num (stmt, hbb, ssa_map);
   else if (strcmp (name, "hsa_set_debug_value") == 0)
     {
       /* FIXME: show warning if user uses a different function description.  */
@@ -3537,11 +3524,12 @@ gen_hsa_insns_for_known_library_call (gimple *stmt, hsa_bb *hbb,
 
 	  src = src->get_in_type (BRIG_TYPE_U64, hbb);
 	  set_debug_value (hbb, src);
-	  return true;
 	}
     }
+  else
+    return false;
 
-  return false;
+  return true;
 }
 
 /* Generate HSA instructions for the given kernel call statement CALL.
-- 
2.6.0


[-- Attachment #6: 0005-HSA-do-not-use-__VA_ARGS__.patch --]
[-- Type: text/x-patch, Size: 803 bytes --]

From 91997649ffb7d3a872eaeb2b9bd78d39f5f3a373 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 15 Oct 2015 13:49:42 +0200
Subject: [PATCH 5/8] HSA: do not use ##__VA_ARGS__.

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c: Do not use ##__VA_ARGS__.
---
 gcc/hsa-gen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index dc4aa62..443aff6 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -89,7 +89,7 @@ along with GCC; see the file COPYING3.  If not see
     hsa_fail_cfun (); \
     if (warning_at (EXPR_LOCATION (hsa_cfun->decl), OPT_Whsa, \
 		    HSA_SORRY_MSG)) \
-      inform (location, message, ##__VA_ARGS__); \
+      inform (location, message, __VA_ARGS__); \
   } \
   while (false);
 
-- 
2.6.0


[-- Attachment #7: 0006-HSA-enhance-tree-hsagen-dumping.patch --]
[-- Type: text/x-patch, Size: 900 bytes --]

From 15c3146141ef8ca6ce3ffabc163b716d58b37204 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 15 Oct 2015 14:22:10 +0200
Subject: [PATCH 6/8] HSA: enhance tree-hsagen dumping.

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* hsa-dump.c (dump_hsa_insn_1): Fix emission if insns have assigned
	numbers.
---
 gcc/hsa-dump.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/hsa-dump.c b/gcc/hsa-dump.c
index 7211d02..0e0acd2 100644
--- a/gcc/hsa-dump.c
+++ b/gcc/hsa-dump.c
@@ -771,11 +771,12 @@ static void
 dump_hsa_insn_1 (FILE *f, hsa_insn_basic *insn, int *indent)
 {
   gcc_checking_assert (insn);
-  indent_stream (f, *indent);
 
   if (insn->number)
     fprintf (f, "%5d: ", insn->number);
 
+  indent_stream (f, *indent);
+
   if (is_a <hsa_insn_phi *> (insn))
     {
       hsa_insn_phi *phi = as_a <hsa_insn_phi *> (insn);
-- 
2.6.0


[-- Attachment #8: 0007-HSA-add-new-hsa_seen_error-guards.patch --]
[-- Type: text/x-patch, Size: 2565 bytes --]

From f5af2c1d61c925aed02ebca69f6339044ead9458 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 15 Oct 2015 16:04:44 +0200
Subject: [PATCH 7/8] HSA: add new hsa_seen_error guards.

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c (gen_function_def_parameters): Add new hsa_seen_error
	guards.
	(gen_hsa_insns_for_direct_call): Likewise.
---
 gcc/hsa-gen.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 443aff6..f35d6ac 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -3189,6 +3189,10 @@ gen_hsa_insns_for_direct_call (gimple *stmt, hsa_bb *hbb,
 
       BrigType16_t mtype = mem_type_for_type (hsa_type_for_scalar_tree_type
 					      (TREE_TYPE (parm), false));
+
+      if (hsa_seen_error ())
+	return;
+
       hsa_op_address *addr = gen_hsa_addr_for_arg (TREE_TYPE (parm), i);
       hsa_op_base *src = hsa_reg_or_immed_for_gimple_op (parm, hbb, ssa_map);
       hsa_insn_mem *mem = new hsa_insn_mem (BRIG_OPCODE_ST, mtype, src, addr);
@@ -3222,8 +3226,21 @@ gen_hsa_insns_for_direct_call (gimple *stmt, hsa_bb *hbb,
 	 declaration for the result.  */
       if (result)
 	{
+	  tree lhs_type = TREE_TYPE (result);
+	  if (AGGREGATE_TYPE_P (lhs_type))
+	    {
+	      HSA_SORRY_ATV (gimple_location (stmt), "support for HSA does not "
+			     "implement assignment of a returned value "
+			     "which is of an aggregate type %T", lhs_type);
+	      return;
+	    }
+
 	  BrigType16_t mtype = mem_type_for_type
-	    (hsa_type_for_scalar_tree_type (TREE_TYPE (result), false));
+	    (hsa_type_for_scalar_tree_type (lhs_type, false));
+
+	  if (hsa_seen_error ())
+	    return;
+
 	  hsa_op_reg *dst = hsa_reg_for_gimple_ssa (result, ssa_map);
 
 	  result_insn = new hsa_insn_mem (BRIG_OPCODE_LD, mtype, dst, addr);
@@ -4873,6 +4890,10 @@ gen_function_def_parameters (hsa_function_representation *f,
       struct hsa_symbol **slot;
 
       fillup_sym_for_decl (parm, &f->input_args[i]);
+
+      if (hsa_seen_error ())
+	return;
+
       f->input_args[i].segment = f->kern_p ? BRIG_SEGMENT_KERNARG :
 				       BRIG_SEGMENT_ARG;
 
@@ -4909,6 +4930,10 @@ gen_function_def_parameters (hsa_function_representation *f,
 
       f->output_arg = XCNEW (hsa_symbol);
       fillup_sym_for_decl (DECL_RESULT (cfun->decl), f->output_arg);
+
+      if (hsa_seen_error ())
+	return;
+
       f->output_arg->segment = BRIG_SEGMENT_ARG;
       f->output_arg->linkage = BRIG_LINKAGE_FUNCTION;
       f->output_arg->name = "res";
-- 
2.6.0


[-- Attachment #9: 0008-HSA-give-up-HSA-code-emission-if-fgnu-tm-is-passed.patch --]
[-- Type: text/x-patch, Size: 927 bytes --]

From dc51075a0dead1abffa9a04903800ae16cab060b Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 15 Oct 2015 17:04:26 +0200
Subject: [PATCH 8/8] HSA: give up HSA code emission if -fgnu-tm is passed.

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* hsa-gen.c (generate_hsa): Produce seen error if
	-fgnu-tm is passed.
---
 gcc/hsa-gen.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index f35d6ac..0174a3c 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -5257,6 +5257,13 @@ generate_hsa (bool kernel)
   hsa_cfun = new hsa_function_representation (cfun->decl, kernel);
   hsa_init_data_for_cfun ();
 
+  if (flag_tm)
+    {
+      HSA_SORRY_AT (UNKNOWN_LOCATION,
+		    "support for HSA does not implement transactional memory");
+      goto fail;
+    }
+
   verify_function_arguments (cfun->decl);
   if (hsa_seen_error ())
     goto fail;
-- 
2.6.0


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

only message in thread, other threads:[~2015-10-16 12:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-16 13:03 [HSA] HSA back-end improvement 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).