From patchwork Tue Jul 2 16:47:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1126397 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-504202-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=golang.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="o+jRmIJE"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=golang-org.20150623.gappssmtp.com header.i=@golang-org.20150623.gappssmtp.com header.b="IzKjkAfq"; 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 45dVYh5dvvz9s4Y for ; Wed, 3 Jul 2019 02:48:40 +1000 (AEST) 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=mG/3sem/iu11V0JSG+MKBqFLNyCNmLA7eQul6gfiqvaMmz SpRC2q7ByolJtKQSFuIR0re1ec21GH0o8Ezi+XxRdMG6AZU/D6/cYPbXx1hi4PnL DYQmI/KtlH4D86csSvq521BNPDBRMws0NlrGLnSMlRDBsjA7IS8TSyKJAl4dI= 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=dlQ6SLxZ0ry7LHp0gfXSaP6VwOs=; b=o+jRmIJEuTYTPt0mGfix D5yeyDH9XNC/mAn8fMtElSnZRpYog6YOZ7AvxmoRjgm9ILu+j58+KqHfIwBLj1mZ 4U3q7smEO4r+iXwUvDQ2Pe1wdeQPFabX8UvBUDhMu7jSvQ/NIzd0m+gIjT+I6PJb 1yY+Y1vqNncQCw4kYyYppGw= Received: (qmail 95216 invoked by alias); 2 Jul 2019 16:48:11 -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 95197 invoked by uid 89); 2 Jul 2019 16:48:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.5 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.1 spammy= X-HELO: mail-lj1-f171.google.com Received: from mail-lj1-f171.google.com (HELO mail-lj1-f171.google.com) (209.85.208.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 02 Jul 2019 16:48:08 +0000 Received: by mail-lj1-f171.google.com with SMTP id h10so17635062ljg.0 for ; Tue, 02 Jul 2019 09:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=Vbd1JJTdEA283eutx/T60Ej06szpyJ2eWvS1ArtmrmQ=; b=IzKjkAfqJZjpaqjcx9Yr4gTeffLCX3i1OQDvs2GNmDheMu3cHbEFG76JHEi43K0Vdl 7+0N/uju0CYoKHMiZdevwU/KbwTK1b/mzZviEszf55UT3W3/RiC3paF24aYypapzTqtn 6KTuajXCxZfySc8mjmrw69Qf7ukQziGLl5/baPycpfYNsyDAUPCrwe/Igt4qrhX3SjyV esymKa1VAD9GA3JgC7pzgyM3DdGn5ZzNFm89JKVmDzopXqM8L4vsy7Qb3tNJb81WHKRq rQrQdPFI7pGP9Mahep2iDz7IOPT79zpGiSgEDx8/IOuyVye3rDZejQA7m7d0RPcY8p10 MyqA== MIME-Version: 1.0 From: Ian Lance Taylor Date: Tue, 2 Jul 2019 09:47:53 -0700 Message-ID: Subject: Go patch committed: Use builtin memset for non-pointer memclr To: gcc-patches , gofrontend-dev This patch by Cherry Zhang changes the Go frontend to use the builtin memset function for zeroing a range of memory that doesn't contain any pointers. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 2019-07-02 Cherry Zhang * go-gcc.cc (Gcc_backend::Gcc_backend): Define __builtin_memset. Index: gcc/go/go-gcc.cc =================================================================== --- gcc/go/go-gcc.cc (revision 272608) +++ gcc/go/go-gcc.cc (working copy) @@ -613,6 +613,15 @@ Gcc_backend::Gcc_backend() NULL_TREE), false, false); + // We use __builtin_memset for zeroing data. + this->define_builtin(BUILT_IN_MEMSET, "__builtin_memset", "memset", + build_function_type_list(void_type_node, + ptr_type_node, + integer_type_node, + size_type_node, + NULL_TREE), + false, false); + // Used by runtime/internal/sys and math/bits. this->define_builtin(BUILT_IN_CTZ, "__builtin_ctz", "ctz", build_function_type_list(integer_type_node, Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 272919) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -1e042a49d6f2e95d371301aa7b911522dc5877f4 +7f753feb8df400d6ed17cdbdfb364f7f3a42fb31 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 272624) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -8910,10 +8910,16 @@ Builtin_call_expression::flatten_append( a2 = Expression::make_type_info(element_type, TYPE_INFO_SIZE); a2 = Expression::make_binary(OPERATOR_MULT, a2, ref, loc); - Runtime::Function code = (element_type->has_pointer() - ? Runtime::MEMCLRHASPTR - : Runtime::MEMCLRNOPTR); - call = Runtime::make_call(code, loc, 2, a1, a2); + if (element_type->has_pointer()) + call = Runtime::make_call(Runtime::MEMCLRHASPTR, loc, 2, a1, a2); + else + { + Type* int32_type = Type::lookup_integer_type("int32"); + Expression* zero = + Expression::make_integer_ul(0, int32_type, loc); + call = Runtime::make_call(Runtime::BUILTIN_MEMSET, loc, 3, a1, + zero, a2); + } if (element_type->has_pointer()) { Index: gcc/go/gofrontend/runtime.def =================================================================== --- gcc/go/gofrontend/runtime.def (revision 272624) +++ gcc/go/gofrontend/runtime.def (working copy) @@ -351,10 +351,6 @@ DEF_GO_RUNTIME(GCWRITEBARRIER, "runtime. DEF_GO_RUNTIME(TYPEDMEMMOVE, "runtime.typedmemmove", P3(TYPE, POINTER, POINTER), R0()) -// Clear memory that contains no pointer. -DEF_GO_RUNTIME(MEMCLRNOPTR, "runtime.memclrNoHeapPointers", - P2(POINTER, UINTPTR), R0()) - // Clear memory that contains pointer. DEF_GO_RUNTIME(MEMCLRHASPTR, "runtime.memclrHasPointers", P2(POINTER, UINTPTR), R0()) @@ -414,6 +410,10 @@ DEF_GO_RUNTIME(UNREACHABLE, "__builtin_u DEF_GO_RUNTIME(BUILTIN_MEMMOVE, "__builtin_memmove", P3(POINTER, POINTER, UINTPTR), R0()) +// Memset, used for zeroing memory. +DEF_GO_RUNTIME(BUILTIN_MEMSET, "__builtin_memset", + P3(POINTER, INT32, UINTPTR), R0()) + // Various intrinsics. // Get the caller's PC, used for runtime.getcallerpc. Index: gcc/go/gofrontend/statements.cc =================================================================== --- gcc/go/gofrontend/statements.cc (revision 272608) +++ gcc/go/gofrontend/statements.cc (working copy) @@ -6882,12 +6882,18 @@ For_range_statement::lower_array_range_c Temporary_statement* ts2 = Statement::make_temporary(NULL, e2, loc); b->add_statement(ts2); - Expression* arg1 = Expression::make_temporary_reference(ts1, loc); - Expression* arg2 = Expression::make_temporary_reference(ts2, loc); - Runtime::Function code = (elem_type->has_pointer() - ? Runtime::MEMCLRHASPTR - : Runtime::MEMCLRNOPTR); - Expression* call = Runtime::make_call(code, loc, 2, arg1, arg2); + Expression* ptr_arg = Expression::make_temporary_reference(ts1, loc); + Expression* sz_arg = Expression::make_temporary_reference(ts2, loc); + Expression* call; + if (elem_type->has_pointer()) + call = Runtime::make_call(Runtime::MEMCLRHASPTR, loc, 2, ptr_arg, sz_arg); + else + { + Type* int32_type = Type::lookup_integer_type("int32"); + Expression* zero = Expression::make_integer_ul(0, int32_type, loc); + call = Runtime::make_call(Runtime::BUILTIN_MEMSET, loc, 3, ptr_arg, + zero, sz_arg); + } Statement* cs3 = Statement::make_statement(call, true); b->add_statement(cs3);