From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 110559 invoked by alias); 23 Nov 2016 05:16:45 -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 110434 invoked by uid 89); 23 Nov 2016 05:16:43 -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=x64, zones, prune, 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; Wed, 23 Nov 2016 05:16:33 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c9Pv1-0007jR-3F for gcc-patches@gcc.gnu.org; Wed, 23 Nov 2016 00:16:31 -0500 Received: from pb-smtp2.pobox.com ([64.147.108.71]:60308 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 1c9Pv0-0007jJ-UE for gcc-patches@gcc.gnu.org; Wed, 23 Nov 2016 00:16:27 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id D50C6514C2; Wed, 23 Nov 2016 00:16:23 -0500 (EST) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id CDC20514C1; Wed, 23 Nov 2016 00:16:23 -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 342ED514BB; Wed, 23 Nov 2016 00:16:22 -0500 (EST) From: Daniel Santos To: gcc-patches Cc: Daniel Santos Subject: [PATCH 6/9] Modify ix86_compute_frame_layout for foutline-msabi-xlogues Date: Wed, 23 Nov 2016 05:16:00 -0000 Message-Id: <20161123051918.22517-6-daniel.santos@pobox.com> In-Reply-To: <25abd41b-923b-2fea-dfc3-9051af632f44@pobox.com> References: <25abd41b-923b-2fea-dfc3-9051af632f44@pobox.com> X-Pobox-Relay-ID: F9CD1AB2-B13B-11E6-A47A-B2917B1B28F4-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: 2016-11/txt/msg02300.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. --- gcc/config/i386/i386.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 131 insertions(+), 7 deletions(-) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index f661b3f..1dc244e 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -2664,13 +2664,37 @@ struct GTY(()) stack_local_entry { saved frame pointer if frame_pointer_needed <- HARD_FRAME_POINTER - [saved regs] - <- regs_save_offset - [padding0] - - [saved SSE regs] + [Normal case: + + [saved regs] + <- reg_save_offset + [padding0] + + [saved SSE regs] + + ][ms x64 --> sysv with -foutline-msabi-xlogues: + [padding0] + <- Start of out-of-line, stub-saved/restored regs + (see libgcc/config/i386/msabi.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 + [saved regs] Any remaning regs are saved in-line + <- reg_save_offset + [saved SSE regs] not yet verified, but I *think* that there should be no + other SSE regs to save here. + ] <- sse_regs_save_offset - [padding1] | + [padding2] | <- FRAME_POINTER [va_arg registers] | | @@ -2692,6 +2716,7 @@ struct ix86_frame HOST_WIDE_INT hard_frame_pointer_offset; HOST_WIDE_INT stack_pointer_offset; HOST_WIDE_INT hfp_save_offset; + HOST_WIDE_INT outlined_save_offset; HOST_WIDE_INT reg_save_offset; HOST_WIDE_INT sse_reg_save_offset; @@ -12489,6 +12514,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, @@ -12504,6 +12531,45 @@ 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 (TARGET_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: 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_moutline_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; @@ -12572,6 +12638,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; @@ -12584,6 +12704,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 @@ -12591,7 +12715,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; } -- 2.9.0