diff mbox

[hsa-branch] Use hsa_obstack to allocate temporary names

Message ID E1bX813-0004vu-Ot@eggs.gnu.org
State New
Headers show

Commit Message

Martin Jambor Aug. 9, 2016, 2:27 p.m. UTC
Hi,

HSA backend now uses ggc_strdup to allocate name strings for stuff that
doesn't have any and therefore we rely on the garbage collector not
running.  That works but is not nice and since the HSA branch now has an
obstack, not necessary.  This patch changes the allocation to be from
the obstack.  Since I did not want to export the obstack, I have moved
the function instead.

Committed to the branch and queued for committing to trunk later.

Thanks,

Martin

2016-08-04  Martin Jambor  <mjambor@suse.cz>

	* hsa.c (hsa_get_declaration_name): Moved to...
	* hsa-gen.c (hsa_get_declaration_name): ...here.  Allocate
	temporary string on an obstack instead from ggc.
---
 gcc/hsa-gen.c | 30 ++++++++++++++++++++++++++++++
 gcc/hsa.c     | 28 ----------------------------
 2 files changed, 30 insertions(+), 28 deletions(-)
diff mbox

Patch

diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index 0e48377..c578294 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -779,6 +779,36 @@  hsa_needs_cvt (BrigType16_t dtype, BrigType16_t stype)
   return false;
 }
 
+/* Return declaration name if exists.  */
+
+const char *
+hsa_get_declaration_name (tree decl)
+{
+  if (!DECL_NAME (decl))
+    {
+      char buf[64];
+      snprintf (buf, 64, "__hsa_anon_%i", DECL_UID (decl));
+      size_t len = strlen (buf);
+      char *copy = (char *) obstack_alloc (&hsa_obstack, len + 1);
+      memcpy (copy, buf, len + 1);
+      return copy;
+    }
+
+  tree name_tree;
+  if (TREE_CODE (decl) == FUNCTION_DECL
+      || (TREE_CODE (decl) == VAR_DECL && is_global_var (decl)))
+    name_tree = DECL_ASSEMBLER_NAME (decl);
+  else
+    name_tree = DECL_NAME (decl);
+
+  const char *name = IDENTIFIER_POINTER (name_tree);
+  /* User-defined assembly names have prepended asterisk symbol.  */
+  if (name[0] == '*')
+    name++;
+
+  return name;
+}
+
 /* Lookup or create the associated hsa_symbol structure with a given VAR_DECL
    or lookup the hsa_structure corresponding to a PARM_DECL.  */
 
diff --git a/gcc/hsa.c b/gcc/hsa.c
index 01520e8..88058cf 100644
--- a/gcc/hsa.c
+++ b/gcc/hsa.c
@@ -786,34 +786,6 @@  hsa_brig_function_name (const char *p)
   return buf;
 }
 
-/* Return declaration name if exists.  */
-
-const char *
-hsa_get_declaration_name (tree decl)
-{
-  if (!DECL_NAME (decl))
-    {
-      char buf[64];
-      snprintf (buf, 64, "__hsa_anonymous_%i", DECL_UID (decl));
-      const char *ggc_str = ggc_strdup (buf);
-      return ggc_str;
-    }
-
-  tree name_tree;
-  if (TREE_CODE (decl) == FUNCTION_DECL
-      || (TREE_CODE (decl) == VAR_DECL && is_global_var (decl)))
-    name_tree = DECL_ASSEMBLER_NAME (decl);
-  else
-    name_tree = DECL_NAME (decl);
-
-  const char *name = IDENTIFIER_POINTER (name_tree);
-  /* User-defined assembly names have prepended asterisk symbol.  */
-  if (name[0] == '*')
-    name++;
-
-  return name;
-}
-
 /* Add a flatten attribute and disable vectorization for gpu implementation
    function decl GDECL.  */