From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18487 invoked by alias); 7 Feb 2017 18:37:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 18402 invoked by uid 89); 7 Feb 2017 18:37:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=AWL,BAYES_50,SPF_NEUTRAL autolearn=no version=3.3.2 spammy=sk:foutlin, sav, sk:xlogue., xlogue 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, 07 Feb 2017 18:36:53 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbAdE-0002XI-V0 for gcc-patches@gcc.gnu.org; Tue, 07 Feb 2017 13:36:52 -0500 Received: from pb-smtp2.pobox.com ([64.147.108.71]:56139 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 1cbAdE-0002WO-Oq for gcc-patches@gcc.gnu.org; Tue, 07 Feb 2017 13:36:48 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id CF5CB675B7; Tue, 7 Feb 2017 13:36:43 -0500 (EST) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id C4F30675B6; Tue, 7 Feb 2017 13:36:43 -0500 (EST) Received: from localhost.localdomain (unknown [76.215.41.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id D70AD675B2; Tue, 7 Feb 2017 13:36:41 -0500 (EST) From: Daniel Santos To: gcc-patches , Uros Bizjak , Jan Hubicka Subject: [PATCH 5/8] [i386] Modify ix86_compute_frame_layout for foutline-msabi-xlogues Date: Tue, 07 Feb 2017 18:37:00 -0000 Message-Id: <20170207184023.19155-5-daniel.santos@pobox.com> In-Reply-To: <2fd14fe7-8d06-45ab-fb1e-96c9c8f4c03b@pobox.com> References: <2fd14fe7-8d06-45ab-fb1e-96c9c8f4c03b@pobox.com> X-Pobox-Relay-ID: 5F301742-ED64-11E6-B76C-A7617B1B28F4-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 X-SW-Source: 2017-02/txt/msg00552.txt.bz2 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. Signed-off-by: Daniel Santos --- gcc/config/i386/i386.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index d52533103f5..249d189ef46 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -2712,12 +2712,29 @@ struct GTY(()) stack_local_entry { saved frame pointer if frame_pointer_needed <- HARD_FRAME_POINTER [saved regs] - <- regs_save_offset + <- reg_save_offset [padding0] <- stack_realign_offset [saved SSE regs] + OR + [stub-saved registers for ms x64 --> sysv clobbers + <- Start of out-of-line, stub-saved/restored regs + (see libgcc/config/i386/(sav|res)ms64*.S) + [XMM6-15] + [RSI] + [RDI] + [?RBX] only if RBX is clobbered + [?RBP] only if RBP and RBX are clobbered + [?R12] only if R12 and all previous regs are clobbered + [?R13] only if R13 and all previous regs are clobbered + [?R14] only if R14 and all previous regs are clobbered + [?R15] only if R15 and all previous regs are clobbered + <- end of stub-saved/restored regs + [padding1] + ] + <- outlined_save_offset <- sse_regs_save_offset - [padding1] | + [padding2] | <- FRAME_POINTER [va_arg registers] | | @@ -2742,6 +2759,7 @@ struct ix86_frame HOST_WIDE_INT reg_save_offset; HOST_WIDE_INT stack_realign_allocate_offset; HOST_WIDE_INT stack_realign_offset; + HOST_WIDE_INT outlined_save_offset; HOST_WIDE_INT sse_reg_save_offset; /* When save_regs_using_mov is set, emit prologue using @@ -12647,6 +12665,22 @@ ix86_builtin_setjmp_frame_value (void) return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx; } +/* Disables out-of-lined msabi to sysv pro/epilogues and emits a warning if + warn_once is null, or *warn_once is zero. */ +static void disable_outline_msabi_xlogues (int *warn_once, const char *msg) +{ + cfun->machine->outline_ms_sysv = false; + if (!warn_once || !*warn_once) + { + warning (OPT_moutline_msabi_xlogues, + "Out-of-lining pro/epilogues for Microsoft ABI functions is " + "not currently compatible with %s%s.", msg, + !warn_once ? ", and is disabled for this function" : ""); + } + if (warn_once) + *warn_once = 1; +} + /* When using -fsplit-stack, the allocation routines set a field in the TCB to the bottom of the stack plus this much space, measured in bytes. */ @@ -12665,9 +12699,54 @@ ix86_compute_frame_layout (struct ix86_frame *frame) HOST_WIDE_INT size = get_frame_size (); HOST_WIDE_INT to_allocate; + CLEAR_HARD_REG_SET (stub_managed_regs); + + /* m->outline_ms_sysv is initially enabled in ix86_expand_call for all 64-bit + * ms_abi functions that call a sysv function. We now need to prune away + * cases where it should be disabled. */ + if (TARGET_64BIT && m->outline_ms_sysv) + { + static int warned_seh; + + gcc_assert (TARGET_64BIT_MS_ABI); + gcc_assert (TARGET_OUTLINE_MSABI_XLOGUES); + + 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: Cases not yet examined. */ + else if (TARGET_SEH) + disable_outline_msabi_xlogues (&warned_seh, + "Structured Exception Handling (SEH)"); + else if (crtl->calls_eh_return) + disable_outline_msabi_xlogues (NULL, "__builtin_eh_return"); + + else if (ix86_static_chain_on_stack) + disable_outline_msabi_xlogues (NULL, "static call chains"); + + else if (ix86_using_red_zone ()) + disable_outline_msabi_xlogues (NULL, "red zones"); + + else if (flag_split_stack) + disable_outline_msabi_xlogues (NULL, "split stack"); + + /* Finally, compute which registers the stub will manage. */ + else + { + unsigned count = xlogue_layout + ::compute_stub_managed_regs (stub_managed_regs); + m->outline_ms_sysv_extra_regs = count - xlogue_layout::MIN_REGS; + } + } + frame->nregs = ix86_nsaved_regs (); frame->nsseregs = ix86_nsaved_sseregs (); - CLEAR_HARD_REG_SET (stub_managed_regs); + m->outline_ms_sysv_pad_in = 0; + m->outline_ms_sysv_pad_out = 0; /* 64-bit MS ABI seem to require stack alignment to be always 16, except for function prologues, leaf functions and when the defult @@ -12771,8 +12850,26 @@ ix86_compute_frame_layout (struct ix86_frame *frame) offset = ROUND_UP (offset, stack_alignment_needed); frame->stack_realign_offset = offset; + if (TARGET_64BIT && m->outline_ms_sysv) + { + gcc_assert (stack_alignment_needed >= 16); + gcc_assert (!frame->nsseregs); + + m->outline_ms_sysv_pad_in = !!(offset & UNITS_PER_WORD); + + /* Select an appropriate layout for incoming stack offset. */ + const struct xlogue_layout &xlogue = xlogue_layout::get_instance (); + + if ((offset + xlogue.get_stack_space_used ()) & UNITS_PER_WORD) + m->outline_ms_sysv_pad_out = 1; + + offset += xlogue.get_stack_space_used (); + gcc_assert (!(offset & 0xf)); + frame->outlined_save_offset = offset; + } + /* Align and set SSE register save area. */ - if (frame->nsseregs) + else if (frame->nsseregs) { /* The only ABI that has saved SSE registers (Win64) also has a 16-byte aligned default stack. However, many programs violate -- 2.11.0