diff mbox

[hsa] Fix omp declare target support

Message ID 20150825142206.GE32341@virgil.suse.cz
State New
Headers show

Commit Message

Martin Jambor Aug. 25, 2015, 2:22 p.m. UTC
Hi,

it was brought to my attention that omp declare target functions were
not properly translated to HSA functions.  Until the grand shceme with
an IPA pass is complete, this will do.  And having a single predicate
to decide what should be an HSA function cannot be bad.  Committed to
the hsa branch.

Thanks,

Martin


2015-08-25  Martin Jambor  <mjambor@suse.cz>

	* hsa.h (hsa_callable_function_p): Declare.
	* hsa.c (hsa_callable_function_p): New function.
	* hsa-gen.c (gen_hsa_insns_for_call): Use it.
	(pass_gen_hsail::execute): Likewise.
---
 gcc/ChangeLog.hsa | 7 +++++++
 gcc/hsa-gen.c     | 5 ++---
 gcc/hsa.c         | 9 +++++++++
 gcc/hsa.h         | 1 +
 4 files changed, 19 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/gcc/ChangeLog.hsa b/gcc/ChangeLog.hsa
index 4ad8414..922c917 100644
--- a/gcc/ChangeLog.hsa
+++ b/gcc/ChangeLog.hsa
@@ -1,5 +1,12 @@ 
 2015-08-25  Martin Jambor  <mjambor@suse.cz>
 
+	* hsa.h (hsa_callable_function_p): Declare.
+	* hsa.c (hsa_callable_function_p): New function.
+	* hsa-gen.c (gen_hsa_insns_for_call): Use it.
+	(pass_gen_hsail::execute): Likewise.
+
+2015-08-25  Martin Jambor  <mjambor@suse.cz>
+
 	* hsa-gen.c (gen_hsa_unaryop_for_builtin): New function.
 
 2015-08-25  Martin Jambor  <mjambor@suse.cz>
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 1e23996..7190dce 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -3255,7 +3255,7 @@  gen_hsa_insns_for_call (gimple stmt, hsa_bb *hbb,
 	  return;
 	}
 
-      if (lookup_attribute ("hsafunc", DECL_ATTRIBUTES (function_decl)))
+      if (hsa_callable_function_p (function_decl))
         gen_hsa_insns_for_direct_call (stmt, hbb, ssa_map);
       else if (!gen_hsa_insns_for_known_library_call (stmt, hbb, ssa_map))
 	sorry ("HSA does support only call for functions with 'hsafunc' "
@@ -4102,8 +4102,7 @@  pass_gen_hsail::execute (function *)
       || lookup_attribute ("hsakernel",
 			   DECL_ATTRIBUTES (current_function_decl)))
     return generate_hsa (true);
-  else if (lookup_attribute ("hsafunc",
-			     DECL_ATTRIBUTES (current_function_decl)))
+  else if (hsa_callable_function_p (current_function_decl))
     return generate_hsa (false);
   else
     return wrap_all_hsa_calls ();
diff --git a/gcc/hsa.c b/gcc/hsa.c
index 13a2ace..4ad44fe 100644
--- a/gcc/hsa.c
+++ b/gcc/hsa.c
@@ -103,6 +103,15 @@  hash_table <hsa_free_symbol_hasher> *hsa_global_variable_symbols;
 /* True if compilation unit-wide data are already allocated and initialized.  */
 static bool compilation_unit_data_initialized;
 
+/* Return true if FNDECL represents an HSA-callable function.  */
+
+bool
+hsa_callable_function_p (tree fndecl)
+{
+  return lookup_attribute ("hsafunc", DECL_ATTRIBUTES (fndecl))
+    || lookup_attribute ("omp declare target", DECL_ATTRIBUTES (fndecl));
+}
+
 /* Allocate HSA structures that are are used when dealing with different
    functions.  */
 
diff --git a/gcc/hsa.h b/gcc/hsa.h
index 3956676..f9bcc80 100644
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -898,6 +898,7 @@  extern struct hsa_function_representation *hsa_cfun;
 extern hash_table <hsa_free_symbol_hasher> *hsa_global_variable_symbols;
 extern hash_map <tree, vec <char *> *> *hsa_decl_kernel_dependencies;
 extern unsigned hsa_kernel_calls_counter;
+bool hsa_callable_function_p (tree fndecl);
 void hsa_init_compilation_unit_data (void);
 void hsa_deinit_compilation_unit_data (void);
 bool hsa_machine_large_p (void);