From 431f76e7d9728f2a722160c2a4c419beab169c72 Mon Sep 17 00:00:00 2001 From: Martin Jambor Date: Tue, 9 Aug 2016 14:08:26 +0000 Subject: Use hsa_obstack to allocate temporary names 2016-08-09 Martin Jambor * 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. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/hsa@239284 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog.hsa | 6 ++++++ gcc/hsa-gen.c | 30 ++++++++++++++++++++++++++++++ gcc/hsa.c | 28 ---------------------------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/gcc/ChangeLog.hsa b/gcc/ChangeLog.hsa index 6ce134c15a3..994a65cf145 100644 --- a/gcc/ChangeLog.hsa +++ b/gcc/ChangeLog.hsa @@ -1,3 +1,9 @@ +2016-08-09 Martin Jambor + + * 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. + 2016-08-09 Martin Jambor * hsa-brig.c (hsa_output_kernels): Remove unnecessary building of diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c index 0e48377cb5e..c578294c6d7 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 01520e821e0..88058cf27fe 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. */ -- cgit v1.2.3