From: Daniel Santos <daniel.santos@pobox.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Daniel Santos <daniel.santos@pobox.com>
Subject: [PATCH 6/9] Modify ix86_compute_frame_layout for foutline-msabi-xlogues
Date: Wed, 23 Nov 2016 05:16:00 -0000 [thread overview]
Message-ID: <20161123051918.22517-6-daniel.santos@pobox.com> (raw)
In-Reply-To: <25abd41b-923b-2fea-dfc3-9051af632f44@pobox.com>
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
next prev parent reply other threads:[~2016-11-23 5:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-23 5:11 [PATCH v2 0/9] Add optimization -moutline-msabi-xlougues (for Wine 64) Daniel Santos
2016-11-23 5:16 ` [PATCH 3/9] Add option -moutline-msabi-xlogues Daniel Santos
2016-11-25 23:51 ` Sandra Loosemore
2016-11-26 1:27 ` Daniel Santos
2016-11-23 5:16 ` [PATCH 8/9] Add msabi pro/epilogue stubs to libgcc Daniel Santos
2016-11-23 5:16 ` Daniel Santos [this message]
2016-11-23 5:16 ` [PATCH 9/9] Add remainder of moutline-msabi-xlogues implementation Daniel Santos
2016-11-23 5:16 ` [PATCH 5/9] Modify ix86_save_reg to optionally omit stub-managed registers Daniel Santos
2016-11-23 5:16 ` [PATCH 1/9] Change type of x86_64_ms_sysv_extra_clobbered_registers Daniel Santos
2016-11-23 5:16 ` [PATCH 4/9] Adds class xlouge_layout and new fields to struct machine_function Daniel Santos
2016-11-23 5:16 ` [PATCH 2/9] Minor refactor in ix86_compute_frame_layout Daniel Santos
2016-11-23 5:16 ` [PATCH 7/9] Add patterns and predicates foutline-msabi-xlouges Daniel Santos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161123051918.22517-6-daniel.santos@pobox.com \
--to=daniel.santos@pobox.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).