From patchwork Tue Jan 9 23:57:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 857842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-470631-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="d2Ap5uTf"; dkim-atps=neutral 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 3zGTb20W9sz9sRm for ; Wed, 10 Jan 2018 10:57:16 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=iAqlbEGe9/dm0JqS6jv2c4oWRLn0iyCbRqZ9gYOuGrvpe0 c9LFYjSjeSzngEVu3Bl+GRLvm68UBZZPLIxPdh0mm2/fLBWUEnYQ5fSRJqsnUK2/ Dh3AUQ++sX92Y9D6DZpyk5+HF78m5tXwGKwxItb8p2hjyATuWVigdSrDGJ9gI= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=TWFpLwKXs6/0eVknL0tkieoaTek=; b=d2Ap5uTfykWPQTtAfSyL STYAtKyNP4nIDiQ2SeQ+yDPENgFaCzVsFC24kaMFbiujoedJ5WX496ibH3eOJ8RV 2xEc1nx/rUaQiO7zEorp+0Gi+rec5DQrMLkCvMZLcFnMcgv3YBFnBPexvg7XbuER sToTCtJCKouNHWTjF6twpwE= Received: (qmail 43506 invoked by alias); 9 Jan 2018 23:57:09 -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 43495 invoked by uid 89); 9 Jan 2018 23:57:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f66.google.com Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 Jan 2018 23:57:07 +0000 Received: by mail-wm0-f66.google.com with SMTP id 123so3011657wme.0 for ; Tue, 09 Jan 2018 15:57:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=AELgtlrrzlqIP1RpCEdPaq6Nj0X3FA60FuKGaJNpCUQ=; b=qZJvwKSLyQnaHMzHc/bOMB6I3KIBEBxg8VY47BFhGQnqkov9Cqdw8OtypxAakU1qpP l36AnOzYx4OzacGmKGB5FtGSxD1v6u7/NFW4nIgTPQRC982ummM+ubopRBXvLG0JAKVm Rv7VwU8awqA3eX9RfcZz8ELH8nR58YsuvKw+aZfgBRJ/poWE5uy/VU1FI5xgoUD/v221 QxQaZry6C5Lv+QlHHwIv33i4lMnup+5OJ6uJYHYQsN3K2FY5XXXrIOfso9rm5idXTePD 3KzbibLV4Yk0g5JJM7qAReAtNxTRqDMTf1j3/rGq3mx49X5UqG/eJK5vkkpGBQ2Zjy2k mu0A== X-Gm-Message-State: AKGB3mJjf4SJ0ItPgGXzYgnQfu8zqI1cM0/3UTVAGPuUcEvG0X4B9WxX roj7BoQl07oVbpf9f9wd01es/nm6R9y9ifGY+zOgmFT9 X-Google-Smtp-Source: ACJfBoshX0ZrZVB5v1He6w5bbXzeebCTx3W9Sw8hxCyzbSECS249LfmIO9zY8ggKYKZB4Nkawep+6+2S4/jJ2cbM6xo= X-Received: by 10.80.177.28 with SMTP id k28mr23047197edd.124.1515542225120; Tue, 09 Jan 2018 15:57:05 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.179.221 with HTTP; Tue, 9 Jan 2018 15:57:04 -0800 (PST) From: Ian Lance Taylor Date: Tue, 9 Jan 2018 15:57:04 -0800 Message-ID: Subject: Go patch committed: Use temporary variable for stack allocation To: gcc-patches , gofrontend-dev@googlegroups.com This patch to the Go frontend by Cherry Zhang uses a temporary variable for stack allocation when possible. Currently, an allocation expression that can be allocated on stack is implemented with __builtin_alloca, which turns into __morestack_allocate_stack_space, which may call the C malloc function. This may be slow. Also if this happens during certain runtime functions (e.g. write barrier), bad things might happen (when the escape analysis is enabled for the runtime). Make a temporary variable on stack for the allocation instead. Also remove the write barrier in the assignment in building heap expression when it is stack allocated. Bootstrapped on x86_64-pc-linux-gnu. Committed to mainline. Ian Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 256411) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -bea521d1d8688bea5b14b1ae2a03aec949f48a44 +7ef1b48f63c0a64b83fc049884fb89677e19b2dd The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 256407) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -12387,6 +12387,7 @@ Allocation_expression::do_get_backend(Tr { Gogo* gogo = context->gogo(); Location loc = this->location(); + Btype* btype = this->type_->get_backend(gogo); if (this->allocate_on_stack_) { @@ -12397,10 +12398,20 @@ Allocation_expression::do_get_backend(Tr go_assert(saw_errors()); return gogo->backend()->error_expression(); } - return gogo->backend()->stack_allocation_expression(size, loc); + Bstatement* decl; + Named_object* fn = context->function(); + go_assert(fn != NULL); + Bfunction* fndecl = fn->func_value()->get_or_make_decl(gogo, fn); + Bexpression* zero = gogo->backend()->zero_expression(btype); + Bvariable* temp = + gogo->backend()->temporary_variable(fndecl, context->bblock(), btype, + zero, true, loc, &decl); + Bexpression* ret = gogo->backend()->var_expression(temp, loc); + ret = gogo->backend()->address_expression(ret, loc); + ret = gogo->backend()->compound_expression(decl, ret, loc); + return ret; } - Btype* btype = this->type_->get_backend(gogo); Bexpression* space = gogo->allocate_memory(this->type_, loc)->get_backend(context); Btype* pbtype = gogo->backend()->pointer_type(btype); @@ -14278,7 +14289,7 @@ Heap_expression::do_get_backend(Translat // don't do this in the write barrier pass because in some cases // backend conversion can introduce new Heap_expression values. Bstatement* assn; - if (!etype->has_pointer()) + if (!etype->has_pointer() || this->allocate_on_stack_) { space = gogo->backend()->var_expression(space_temp, loc); Bexpression* ref =