From patchwork Tue Aug 9 14:27:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 657283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s7xVb5v1vz9sBM for ; Wed, 10 Aug 2016 00:29:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=RYQbYqfi; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :resent-from:resent-date:resent-message-id:resent-to:from:date :subject:to:message-id; q=dns; s=default; b=Ko9g09OjMH3VgBk9a5jz RIwTIdy5xTQm/WpOkxKMVjYzR0gLEG2B27amnK2Oe1gF7dXsflrPWDa+eacBq5aZ WcUehhE/5DdHUn0nP/R2f7UCmmT69T5Y6zTPQSGHzOU8A5USrC7xlXbwk4Xu0CgB MC3ZUlXJ0qLipTPK3yIxmWM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :resent-from:resent-date:resent-message-id:resent-to:from:date :subject:to:message-id; s=default; bh=TiX7udWNaBXw9DBRfMFgBIOWPO o=; b=RYQbYqfifT7O6+9YxmfTOKLomRMTpSAImoVTdxAAZflNkGj3tEA7/7gAuC nh4vJWs27h2AK+UtMiU/sCxlWUmuIYqFj0dS2uIoLtEgMDcHGEVU/4yIjobCR06B f3b4842hyaQpO7SO2K69EWo9YINjFlSBPaqmYQ/OrpSImueTs= Received: (qmail 58068 invoked by alias); 9 Aug 2016 14:28:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 57884 invoked by uid 89); 9 Aug 2016 14:28:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=BAYES_00, SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=2016-08-04, H*MI:eggs, H*M:eggs, obstack_alloc X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 09 Aug 2016 14:28:31 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bX813-0004wG-VX for gcc-patches@gcc.gnu.org; Tue, 09 Aug 2016 10:28:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:47641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bX813-0004vu-Ot for gcc-patches@gcc.gnu.org; Tue, 09 Aug 2016 10:28:25 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 86E14ACA3 for ; Tue, 9 Aug 2016 14:28:22 +0000 (UTC) Resent-From: Martin Jambor Resent-Date: Tue, 9 Aug 2016 16:28:22 +0200 Resent-Message-ID: <20160809142822.o36xueiu554hvvbi@virgil.suse.cz> Resent-To: GCC Patches From: Martin Jambor Date: Tue, 9 Aug 2016 16:27:04 +0200 Subject: [hsa-branch] Use hsa_obstack to allocate temporary names To: GCC Patches X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] Message-ID: X-Received-From: 195.135.220.15 X-IsSubscribed: yes 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 * 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 --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. */