Retry to emit global variables in HSA (PR hsa/70234)
authorMartin Liska <mliska@suse.cz>
Mon, 21 Mar 2016 10:27:53 +0000 (11:27 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Mon, 21 Mar 2016 10:27:53 +0000 (10:27 +0000)
PR hsa/70234
* hsa-brig.c (emit_function_directives): Mark unemitted
global variables for emission.
* hsa-gen.c (hsa_symbol::hsa_symbol): Initialize a new flag.
(get_symbol_for_decl): Likewise.
* hsa.h (struct hsa_symbol): New flag.

From-SVN: r234362

gcc/ChangeLog
gcc/hsa-brig.c
gcc/hsa-gen.c
gcc/hsa.h

index 2efe7ea31fa740f3b2f5bbd766684c8bc722ed4b..7a918672563a7df1886a77bb62de15b842614928 100644 (file)
@@ -1,3 +1,12 @@
+2016-03-21  Martin Liska  <mliska@suse.cz>
+
+       PR hsa/70234
+       * hsa-brig.c (emit_function_directives): Mark unemitted
+       global variables for emission.
+       * hsa-gen.c (hsa_symbol::hsa_symbol): Initialize a new flag.
+       (get_symbol_for_decl): Likewise.
+       * hsa.h (struct hsa_symbol): New flag.
+
 2016-03-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/70288
index 2a301be81060928a8519312be15728b9f2677280..9b6c0b888e0ed146f41f019d540071febd413bce 100644 (file)
@@ -643,6 +643,8 @@ emit_function_directives (hsa_function_representation *f, bool is_declaration)
   if (!f->m_declaration_p)
     for (int i = 0; f->m_global_symbols.iterate (i, &sym); i++)
       {
+       gcc_assert (!sym->m_emitted_to_brig);
+       sym->m_emitted_to_brig = true;
        emit_directive_variable (sym);
        brig_insn_count++;
       }
index 5939a577f3f4a2a46d82672e68e16f9aec7f8899..72eecf9462e5dbc3602c8f92efbfd6c94a4c5944 100644 (file)
@@ -162,7 +162,7 @@ hsa_symbol::hsa_symbol ()
     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_allocation (BRIG_ALLOCATION_AUTOMATIC)
+    m_allocation (BRIG_ALLOCATION_AUTOMATIC), m_emitted_to_brig (false)
 {
 }
 
@@ -174,7 +174,7 @@ hsa_symbol::hsa_symbol (BrigType16_t type, BrigSegment8_t segment,
     m_directive_offset (0), m_type (type), m_segment (segment),
     m_linkage (linkage), m_dim (0), m_cst_value (NULL),
     m_global_scope_p (global_scope_p), m_seen_error (false),
-    m_allocation (allocation)
+    m_allocation (allocation), m_emitted_to_brig (false)
 {
 }
 
@@ -880,11 +880,28 @@ get_symbol_for_decl (tree decl)
   gcc_checking_assert (slot);
   if (*slot)
     {
+      hsa_symbol *sym = (*slot);
+
       /* If the symbol is problematic, mark current function also as
         problematic.  */
-      if ((*slot)->m_seen_error)
+      if (sym->m_seen_error)
        hsa_fail_cfun ();
 
+      /* PR hsa/70234: If a global variable was marked to be emitted,
+        but HSAIL generation of a function using the variable fails,
+        we should retry to emit the variable in context of a different
+        function.
+
+        Iterate elements whether a symbol is already in m_global_symbols
+        of not.  */
+        if (is_in_global_vars && !sym->m_emitted_to_brig)
+         {
+           for (unsigned i = 0; i < hsa_cfun->m_global_symbols.length (); i++)
+             if (hsa_cfun->m_global_symbols[i] == sym)
+               return *slot;
+           hsa_cfun->m_global_symbols.safe_push (sym);
+         }
+
       return *slot;
     }
   else
index 6a7c651ce9bc0c9100a0893c9b034c65f15c26ba..1d6baaba9b5136fe7e6539dc631adeab7ef8435d 100644 (file)
--- a/gcc/hsa.h
+++ b/gcc/hsa.h
@@ -110,6 +110,9 @@ struct hsa_symbol
   /* Symbol allocation.  */
   BrigAllocation m_allocation;
 
+  /* Flag used for global variables if a variable is already emitted or not.  */
+  bool m_emitted_to_brig;
+
 private:
   /* Default constructor.  */
   hsa_symbol ();