From patchwork Tue Nov 15 20:06:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Santos X-Patchwork-Id: 695243 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 3tJJKl342Yz9t0v for ; Wed, 16 Nov 2016 07:05:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="kjI6pGxF"; 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:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=Dpt62nEITuFn8yqeSif5rVxjaM01eKvXhcUMAzLxRbCoqzdCFlMQ2 7jiCKL2izZaVeakKhO8WCYj08Qss24CNsaUR+kpxEcNJ84yMJxXz3e206xSgQl41 1JTf85LUiFw5ea0AcrDsw+GsJ7RZJ4/coBWUA+fteMJO10ACZ/41fw= 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:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=nPdUPGIiqtVPTHVk1ywnZ9KDGqA=; b=kjI6pGxFGiX82RIRfhrh NQCXus3g1ze7Ejxi4FObjuhHIm9c2aLXyNubIEbcGaT3GHa0m7i4+Ouod1B3lljr 7ZsnvQrmftt7iquqdcVADXbjLS30hZu3HyAJtBzlh6E2IpX9RpKdmAOYF/W57TCv a9GhX/N1DDG9lYhEueqRtik= Received: (qmail 50198 invoked by alias); 15 Nov 2016 20:03:51 -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 49654 invoked by uid 89); 15 Nov 2016 20:03:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, SPF_NEUTRAL autolearn=no version=3.3.2 spammy=HX-detected-operating-system:fuzzy, zones, incoming 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 ESMTP; Tue, 15 Nov 2016 20:03:39 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6jxA-0007Zl-1k for gcc-patches@gcc.gnu.org; Tue, 15 Nov 2016 15:03:37 -0500 Received: from pb-smtp2.pobox.com ([64.147.108.71]:64553 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c6jx9-0007Zh-UB for gcc-patches@gcc.gnu.org; Tue, 15 Nov 2016 15:03:35 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 8AF0A4E2D7; Tue, 15 Nov 2016 15:03:35 -0500 (EST) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 735894E2D3; Tue, 15 Nov 2016 15:03:35 -0500 (EST) Received: from localhost.localdomain (unknown [76.215.41.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id C3EA24E2CF; Tue, 15 Nov 2016 15:03:33 -0500 (EST) From: Daniel Santos To: gcc-patches Cc: Daniel Santos Subject: [PATCH 8/9] Modify ix86_compute_frame_layout for foutline-msabi-xlogues Date: Tue, 15 Nov 2016 14:06:59 -0600 Message-Id: <20161115200700.10792-8-daniel.santos@pobox.com> In-Reply-To: <79f0ea00-ed47-1ee3-8efd-f57027426970@pobox.com> References: <79f0ea00-ed47-1ee3-8efd-f57027426970@pobox.com> X-Pobox-Relay-ID: 96FF2588-AB6E-11E6-9B99-3AB77A1B28F4-06139138!pb-smtp2.pobox.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.147.108.71 X-IsSubscribed: yes ix86_compute_frame_layout will now populate fields added to structs machine_function and ix86_frame and modify the frame layout specific to facilitate the use of save & restore stubs. --- gcc/config/i386/i386.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index cb4e688..f3149ef 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -12516,6 +12516,8 @@ ix86_compute_frame_layout (struct ix86_frame *frame) frame->nregs = ix86_nsaved_regs (); frame->nsseregs = ix86_nsaved_sseregs (); + m->outline_ms_sysv_pad_in = 0; + m->outline_ms_sysv_pad_out = 0; CLEAR_HARD_REG_SET (stub_managed_regs); /* 64-bit MS ABI seem to require stack alignment to be always 16, @@ -12531,6 +12533,61 @@ ix86_compute_frame_layout (struct ix86_frame *frame) crtl->stack_alignment_needed = 128; } + /* m->outline_ms_sysv is initially enabled in ix86_expand_call for all + 64-bit ms_abi functions that call a sysv function. So this is where + we prune away cases where actually don't want to out-of-line the + pro/epilogues. */ + if (m->outline_ms_sysv) + { + gcc_assert (TARGET_64BIT_MS_ABI); + gcc_assert (flag_outline_msabi_xlogues); + + /* Do we need to handle SEH and disable the optimization? */ + gcc_assert (!TARGET_SEH); + + if (!TARGET_SSE) + m->outline_ms_sysv = false; + + /* Don't break hot-patched functions. */ + else if (ix86_function_ms_hook_prologue (current_function_decl)) + m->outline_ms_sysv = false; + + /* TODO: Still need to add support for hard frame pointers when stack + realignment is not needed. */ + else if (crtl->stack_realign_finalized + && (frame_pointer_needed && !crtl->stack_realign_needed)) + { + static bool warned = false; + if (!warned) + { + warned = true; + warning (OPT_foutline_msabi_xlogues, + "not currently supported with hard frame pointers when " + "not realigning stack."); + } + m->outline_ms_sysv = false; + } + + /* TODO: Cases that have not yet been examined. */ + else if (crtl->calls_eh_return + || crtl->need_drap + || m->static_chain_on_stack + || ix86_using_red_zone () + || flag_split_stack) + { + static bool warned = false; + if (!warned) + { + warned = true; + warning (OPT_foutline_msabi_xlogues, + "not currently supported with the following: SEH, " + "DRAP, static call chains on the stack, red zones or " + "split stack."); + } + m->outline_ms_sysv = false; + } + } + stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT; preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT; @@ -12599,6 +12656,60 @@ ix86_compute_frame_layout (struct ix86_frame *frame) /* The traditional frame pointer location is at the top of the frame. */ frame->hard_frame_pointer_offset = offset; + if (m->outline_ms_sysv) + { + unsigned i; + HOST_WIDE_INT offset_after_int_regs; + + gcc_assert (!(offset & 7)); + + /* Select an appropriate layout for incoming stack offset. */ + m->outline_ms_sysv_pad_in = (!crtl->stack_realign_needed && (offset & 8)); + const struct xlogue_layout &xlogue = xlogue_layout::get_instance (); + + gcc_assert (frame->nregs >= 2); + gcc_assert (frame->nsseregs >= 10); + + for (i = 0; i < xlogue.get_nregs (); ++i) + { + unsigned regno = xlogue.get_reginfo (i).regno; + + if (ix86_save_reg (regno, false, false)) + { + add_to_hard_reg_set (&stub_managed_regs, DImode, regno); + /* For the purposes of pro/epilogue generation, we'll only count + regs that aren't saved/restored by out-of-line stubs. */ + if (SSE_REGNO_P (regno)) + --frame->nsseregs; + else + --frame->nregs; + } + else + break; + } + + gcc_assert (i >= xlogue_layout::MIN_REGS); + gcc_assert (i <= xlogue_layout::MAX_REGS); + gcc_assert (frame->nregs >=0); + gcc_assert (frame->nsseregs >=0); + m->outline_ms_sysv_extra_regs = i - xlogue_layout::MIN_REGS; + + /* If, after saving any remaining int regs we need padding for + 16-byte alignment, we insert that padding prior to remaining int + reg saves. */ + offset_after_int_regs = xlogue.get_stack_space_used () + + frame->nregs * UNITS_PER_WORD; + if (offset_after_int_regs & 8) + { + m->outline_ms_sysv_pad_out = 1; + offset_after_int_regs += UNITS_PER_WORD; + } + + gcc_assert (!(offset_after_int_regs & 15)); + offset += xlogue.get_stack_space_used (); + frame->outlined_save_offset = offset; + } + /* Register save area */ offset += frame->nregs * UNITS_PER_WORD; frame->reg_save_offset = offset; @@ -12611,6 +12722,10 @@ ix86_compute_frame_layout (struct ix86_frame *frame) /* Align and set SSE register save area. */ if (frame->nsseregs) { + if (m->outline_ms_sysv) + /* If stack is not 16-byte aligned here, then bug. */ + gcc_assert (!(offset & 15)); + /* The only ABI that has saved SSE registers (Win64) also has a 16-byte aligned default stack, and thus we don't need to be within the re-aligned local stack frame to save them. In case @@ -12618,7 +12733,7 @@ ix86_compute_frame_layout (struct ix86_frame *frame) unaligned move of SSE register will be emitted, so there is no point to round up the SSE register save area outside the re-aligned local stack frame to 16 bytes. */ - if (ix86_incoming_stack_boundary >= 128) + else if (ix86_incoming_stack_boundary >= 128) offset = ROUND_UP (offset, 16); offset += frame->nsseregs * 16; }