* [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
@ 2017-02-07 18:34 Daniel Santos
2017-02-07 18:36 ` [PATCH 4/8] [i386] Modify ix86_save_reg to optionally omit stub-managed registers Daniel Santos
` (7 more replies)
0 siblings, 8 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-07 18:34 UTC (permalink / raw)
To: gcc-patches, Uros Bizjak, Jan Hubicka, Sandra Loosemore
I apologize to those of you who get this twice, but I accidentally
posted to the wrong list!
Uros or Jan,
Please take this as a ping, as I never bothered pinging after submitting
v2 since I found a few more issues with it. :) Although I realize this
would be a GCC 8 stage 1 item, I would like to try to get it finished up
and tentatively approved as soon as I can. I have tried to summarize
this patch set as clearly and succinctly below as possible. Thanks!
* This patch set depends upon the "Use aligned SSE movs for re-aligned
MS ABI pro/epilogues" patch set:
https://gcc.gnu.org/ml/gcc-patches/2016-12/msg01859.html
* I have submitted a test program submitted separately:
https://gcc.gnu.org/ml/gcc-patches/2017-02/msg00542.html
Summary
=======
When a 64-bit Microsoft function calls and System V function, ABI
differences requires RSI, RDI and XMM6-15 to be considered as
clobbered. Saving these registers inline can cost as much as 109 bytes
and a similar amount for restoring. This patch set targets 64-bit Wine
and aims to mitigate some of these costs by adding ms/sysv save &
restore stubs to libgcc, which are called from pro/epilogues rather than
emitting the code inline. And since we're already tinkering with stubs,
they will also manages the save/restore of all remaining registers if
possible. Analysis of building Wine 64 demonstrates a reduction of
.text by around 20%, which also translates into a reduction of Wine's
install size by 34MiB.
As there will usually only be 3 stubs in memory at any time, I'm using
the larger mov instructions instead of push/pop to facilitate better
parallelization. The basic theory is that the combination of better
parallelization and reduced I-cache misses will offset the extra
instructions required for implementation, although I have not produced
actual performance data yet.
For now, I have called this feature -moutline-msabi-xlogues, but Sandra
Loosemore has this suggestion:
(https://gcc.gnu.org/ml/gcc-patches/2016-11/msg02670.html)
> Just as a suggestion (I'm not an i386 maintainer), I'd recommend
> spelling the name of this option -mno-inline-msabi-xlogues instead of
> -moutline-msabi-xlogues, and making the default -minline-msabi-xlogues.
When enabled, the feature is activated when an ms_abi function calls a
sysv_abi function if the following is true (evaluated in
ix86_compute_frame_layout):
TARGET_SSE
&& !ix86_function_ms_hook_prologue (current_function_decl)
&& !SEH
&& !crtl->calls_eh_return
&& !ix86_static_chain_on_stack
&& !ix86_using_red_zone ()
&& !flag_split_stack
Some of these, like __builtin_eh_return, might be easy to add but I
don't have a test for them.
StackLayout
============
When active, registers are saved on the stack differently. Note that
when not active, stack layout is *unchanged*.
[arguments]
<- ARG_POINTER
saved pc
saved frame pointer if frame_pointer_needed
<- HARD_FRAME_POINTER
[saved regs] if not managed by stub, (e.g. explicitly
clobbered)
<- reg_save_offset
[padding0]
<- stack_realign_offset
<- Start of out-of-line, stub-managed regs
XMM6-15
RSI
RDI
[RBX] if RBX is clobbered
[RBP] if RBP and RBX are clobbered and HFP not used.
[R12] if R12 and all previous regs are clobbered
[R13] if R13 and all previous regs are clobbered
[R14] if R14 and all previous regs are clobbered
[R15] if R15 and all previous regs are clobbered
<- end of stub-saved/restored regs
[padding1]
<- outlined_save_offset
<- sse_regs_save_offset
[padding2]
<- FRAME_POINTER
[va_arg registers]
[frame]
... etc.
Stubs
=====
There are two sets of stubs for use with and without hard frame
pointers. Each set has a save, a restore and a restore-as-tail-call
that performs the function's return. Each stub has entry points for the
number of registers it's saving. The non-tail-call restore is used when
a sibling call is the tail. If a normal register is explicitly
clobbered out of the order that hard registers are usually assigned in
(e.g., __asm__ __volatile__ ("":::"r15")), then that register will be
saved and restored as normal and not by the stub.
Stub names:
__savms64_(12-18)
__resms64_(12-18)
__resms64x_(12-18)
__savms64f_(12-17)
__resms64f_(12-17)
__resms64fx_(12-17)
Save stubs use RAX as a base register and restore stubs use RSI, the
later which is overwritten before returning. Restore-as-tail-call for
the non-HFP case uses R10 to restore the stack pointer before returning.
Samples
=======
Standard case with RBX, RBP and R12 also being used in function:
Prologue:
lea -0x78(%rsp),%rax
sub $0x108,%rsp
callq 5874b <__savms64_15>
Epilogue (r10 stores the value to restore the stack pointer to):
lea 0x90(%rsp),%rsi
lea 0x78(%rsi),%r10
jmpq 587eb <__resms64x_15>
Stack pointer realignment case (same clobbers):
Prologue, stack realignment case:
push %rbp
mov %rsp,%rbp
and $0xfffffffffffffff0,%rsp
lea -0x70(%rsp),%rax
sub $0x100,%rsp
callq 57fc7 <__savms64f_15>
Epilogue, stack realignment case:
lea 0x90(%rsp),%rsi
jmpq 58013 <__resms64fx_15>
Testing
=======
A comprehensive test program is submitted separately with no additional
tests failing. I have also run Wine's tests with no additional failures
(although a few very minor tweaks have gone in since I last ran Wine's
tests). I have not run -flto tests on Wine as I haven't yet found a way
to Wine to build with -flto, maybe I'm just doing it wrong.
Daniel Santos
gcc/config/i386/i386.c | 700
++++++++++++++++++++++++++++++++++++++---
gcc/config/i386/i386.h | 22 +-
gcc/config/i386/i386.opt | 5 +
gcc/config/i386/predicates.md | 155 +++++++++
gcc/config/i386/sse.md | 37 +++
gcc/doc/invoke.texi | 11 +-
libgcc/config.host | 2 +-
libgcc/config/i386/i386-asm.h | 82 +++++
libgcc/config/i386/resms64.S | 57 ++++
libgcc/config/i386/resms64f.S | 55 ++++
libgcc/config/i386/resms64fx.S | 57 ++++
libgcc/config/i386/resms64x.S | 59 ++++
libgcc/config/i386/savms64.S | 57 ++++
libgcc/config/i386/savms64f.S | 55 ++++
libgcc/config/i386/t-msabi | 7 +
15 files changed, 1323 insertions(+), 38 deletions(-)
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 3/8] [i386] Adds class xlouge_layout and new fields to struct machine_function
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
2017-02-07 18:36 ` [PATCH 4/8] [i386] Modify ix86_save_reg to optionally omit stub-managed registers Daniel Santos
2017-02-07 18:36 ` [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues Daniel Santos
@ 2017-02-07 18:36 ` Daniel Santos
2017-02-07 18:37 ` [PATCH 7/8] [i386] Add msabi pro/epilogue stubs to libgcc Daniel Santos
` (4 subsequent siblings)
7 siblings, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-07 18:36 UTC (permalink / raw)
To: gcc-patches, Uros Bizjak, Jan Hubicka
Of the new fields added to struct machine_function, outline_ms_sysv is
initially set in ix86_expand_call, but may later be cleared when
ix86_compute_frame_layout is called (both of these are in subsequent
patch). If it is not cleared, then the remaining new fields will be
set.
The new class xlouge_layout manages the layout of the stack area used by
the out-of-line save & restore stubs as well as any padding needed
before and after the save area. It also provides the proper symbol rtx
for the requested stub based upon values of the new fields in struct
machine_function.
xlouge_layout cannot be used until stack realign flags are finalized and
ix86_compute_frame_layout is called, at which point
xlouge_layout::get_instance may be used to retrieve the appropriate
(constant) instance of xlouge_layout.
Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
gcc/config/i386/i386.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++++
gcc/config/i386/i386.h | 18 ++++
2 files changed, 279 insertions(+)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 9a0dfdc77ba..6449fbb42bb 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -91,6 +91,7 @@ static rtx legitimize_dllimport_symbol (rtx, bool);
static rtx legitimize_pe_coff_extern_decl (rtx, bool);
static rtx legitimize_pe_coff_symbol (rtx, bool);
static void ix86_print_operand_address_as (FILE *, rtx, addr_space_t, bool);
+static bool ix86_save_reg (unsigned int, bool, bool);
#ifndef CHECK_STACK_LIMIT
#define CHECK_STACK_LIMIT (-1)
@@ -2430,6 +2431,266 @@ unsigned const x86_64_ms_sysv_extra_clobbered_registers[12] =
XMM12_REG, XMM13_REG, XMM14_REG, XMM15_REG
};
+enum xlogue_stub {
+ XLOGUE_STUB_SAVE,
+ XLOGUE_STUB_RESTORE,
+ XLOGUE_STUB_RESTORE_TAIL,
+ XLOGUE_STUB_SAVE_HFP,
+ XLOGUE_STUB_RESTORE_HFP,
+ XLOGUE_STUB_RESTORE_HFP_TAIL,
+
+ XLOGUE_STUB_COUNT
+};
+
+enum xlogue_stub_sets {
+ XLOGUE_SET_ALIGNED,
+ XLOGUE_SET_ALIGNED_PLUS_8,
+ XLOGUE_SET_HFP_ALIGNED_OR_REALIGN,
+ XLOGUE_SET_HFP_ALIGNED_PLUS_8,
+
+ XLOGUE_SET_COUNT
+};
+
+/* Register save/restore layout used by an out-of-line stubs. */
+class xlogue_layout {
+public:
+ struct reginfo
+ {
+ unsigned regno;
+ HOST_WIDE_INT offset; /* Offset used by stub base pointer (rax or
+ rsi) to where each register is stored. */
+ };
+
+ unsigned get_nregs () const {return m_nregs;}
+ HOST_WIDE_INT get_stack_align_off_in () const {return m_stack_align_off_in;}
+
+ const reginfo &get_reginfo (unsigned reg) const
+ {
+ gcc_assert (reg < m_nregs);
+ return m_regs[reg];
+ }
+
+ /* Returns an rtx for the stub's symbol based upon
+ 1.) the specified stub (save, restore or restore_ret) and
+ 2.) the value of cfun->machine->outline_ms_sysv_extra_regs and
+ 3.) rather or not stack alignment is being performed. */
+ rtx get_stub_rtx (enum xlogue_stub stub) const;
+
+ /* Returns the amount of stack space (including padding) that the stub
+ needs to store registers based upon data in the machine_function. */
+ HOST_WIDE_INT get_stack_space_used () const
+ {
+ const struct machine_function &m = *cfun->machine;
+ unsigned last_reg = m.outline_ms_sysv_extra_regs + MIN_REGS - 1;
+
+ gcc_assert (m.outline_ms_sysv_extra_regs <= MAX_EXTRA_REGS);
+ return m_regs[last_reg].offset
+ + (m.outline_ms_sysv_pad_out ? 8 : 0)
+ + STUB_INDEX_OFFSET;
+ }
+
+ /* Returns the offset for the base pointer used by the stub. */
+ HOST_WIDE_INT get_stub_ptr_offset () const
+ {
+ return STUB_INDEX_OFFSET + m_stack_align_off_in;
+ }
+
+ static const struct xlogue_layout &get_instance ();
+ static unsigned compute_stub_managed_regs (HARD_REG_SET &stub_managed_regs);
+
+ static const HOST_WIDE_INT STUB_INDEX_OFFSET = 0x70;
+ static const unsigned MIN_REGS = NUM_X86_64_MS_CLOBBERED_REGS;
+ static const unsigned MAX_REGS = 18;
+ static const unsigned MAX_EXTRA_REGS = MAX_REGS - MIN_REGS;
+ static const unsigned VARIANT_COUNT = MAX_EXTRA_REGS + 1;
+ static const unsigned STUB_NAME_MAX_LEN = 16;
+ static const char * const STUB_BASE_NAMES[XLOGUE_STUB_COUNT];
+ static const unsigned REG_ORDER[MAX_REGS];
+ static const unsigned REG_ORDER_REALIGN[MAX_REGS];
+
+private:
+ xlogue_layout ();
+ xlogue_layout (HOST_WIDE_INT stack_align_off_in, bool hfp);
+ xlogue_layout (const xlogue_layout &);
+
+ /* True if hard frame pointer is used. */
+ bool m_hfp;
+
+ /* Max number of register this layout manages. */
+ unsigned m_nregs;
+
+ /* Incoming offset from 16-byte alignment. */
+ HOST_WIDE_INT m_stack_align_off_in;
+ struct reginfo m_regs[MAX_REGS];
+ rtx m_syms[XLOGUE_STUB_COUNT][VARIANT_COUNT];
+ char m_stub_names[XLOGUE_STUB_COUNT][VARIANT_COUNT][STUB_NAME_MAX_LEN];
+
+ static const struct xlogue_layout GTY(()) s_instances[XLOGUE_SET_COUNT];
+};
+
+const char * const xlogue_layout::STUB_BASE_NAMES[XLOGUE_STUB_COUNT] = {
+ "savms64",
+ "resms64",
+ "resms64x",
+ "savms64f",
+ "resms64f",
+ "resms64fx"
+};
+
+const unsigned xlogue_layout::REG_ORDER[xlogue_layout::MAX_REGS] = {
+/* The below offset values are where each register is stored for the layout
+ relative to incoming stack pointer. The value of each m_regs[].offset will
+ be relative to the incoming base pointer (rax or rsi) used by the stub.
+
+ s_instances: 0 1 2 3
+ Offset: realigned or aligned + 8
+ Register aligned aligned + 8 aligned w/HFP w/HFP */
+ XMM15_REG, /* 0x10 0x18 0x10 0x18 */
+ XMM14_REG, /* 0x20 0x28 0x20 0x28 */
+ XMM13_REG, /* 0x30 0x38 0x30 0x38 */
+ XMM12_REG, /* 0x40 0x48 0x40 0x48 */
+ XMM11_REG, /* 0x50 0x58 0x50 0x58 */
+ XMM10_REG, /* 0x60 0x68 0x60 0x68 */
+ XMM9_REG, /* 0x70 0x78 0x70 0x78 */
+ XMM8_REG, /* 0x80 0x88 0x80 0x88 */
+ XMM7_REG, /* 0x90 0x98 0x90 0x98 */
+ XMM6_REG, /* 0xa0 0xa8 0xa0 0xa8 */
+ SI_REG, /* 0xa8 0xb0 0xa8 0xb0 */
+ DI_REG, /* 0xb0 0xb8 0xb0 0xb8 */
+ BX_REG, /* 0xb8 0xc0 0xb8 0xc0 */
+ BP_REG, /* 0xc0 0xc8 N/A N/A */
+ R12_REG, /* 0xc8 0xd0 0xc0 0xc8 */
+ R13_REG, /* 0xd0 0xd8 0xc8 0xd0 */
+ R14_REG, /* 0xd8 0xe0 0xd0 0xd8 */
+ R15_REG, /* 0xe0 0xe8 0xd8 0xe0 */
+};
+
+/* Instantiates all xlogue_layout instances. */
+const struct xlogue_layout GTY(())
+xlogue_layout::s_instances[XLOGUE_SET_COUNT] = {
+ xlogue_layout (0, false),
+ xlogue_layout (8, false),
+ xlogue_layout (0, true),
+ xlogue_layout (8, true)
+};
+
+/* Return an appropriate const instance of xlogue_layout based upon values
+ in cfun->machine and crtl. */
+const struct xlogue_layout &xlogue_layout::get_instance ()
+{
+ enum xlogue_stub_sets stub_set;
+ bool aligned_plus_8 = cfun->machine->outline_ms_sysv_pad_in;
+
+ if (stack_realign_fp)
+ stub_set = XLOGUE_SET_HFP_ALIGNED_OR_REALIGN;
+ else if (frame_pointer_needed)
+ stub_set = aligned_plus_8
+ ? XLOGUE_SET_HFP_ALIGNED_PLUS_8
+ : XLOGUE_SET_HFP_ALIGNED_OR_REALIGN;
+ else
+ stub_set = aligned_plus_8 ? XLOGUE_SET_ALIGNED_PLUS_8 : XLOGUE_SET_ALIGNED;
+
+ return s_instances[stub_set];
+}
+
+/* Determine which clobbered registers can be saved by the stub and store
+ them in stub_managed_regs. Returns the count of registers the stub will
+ save and restore. */
+unsigned
+xlogue_layout::compute_stub_managed_regs (HARD_REG_SET &stub_managed_regs)
+{
+ bool hfp = frame_pointer_needed || stack_realign_fp;
+
+ unsigned i, count;
+ unsigned regno;
+
+ for (i = 0; i < NUM_X86_64_MS_CLOBBERED_REGS; ++i)
+ {
+ regno = x86_64_ms_sysv_extra_clobbered_registers[i];
+ if (regno == BP_REG && hfp)
+ continue;
+ if (!ix86_save_reg (regno, false, false))
+ return 0;
+ }
+
+ for (count = i = 0; i < MAX_REGS; ++i)
+ {
+ regno = REG_ORDER[i];
+ if (regno == BP_REG && hfp)
+ continue;
+ if (!ix86_save_reg (regno, false, false))
+ break;
+ add_to_hard_reg_set (&stub_managed_regs, DImode, regno);
+ ++count;
+ }
+ gcc_assert (count >= MIN_REGS && count <= MAX_REGS);
+ return count;
+}
+
+/* Constructor for xlogue_layout. */
+xlogue_layout::xlogue_layout (HOST_WIDE_INT stack_align_off_in, bool hfp)
+ : m_hfp (hfp) , m_nregs (hfp ? 17 : 18),
+ m_stack_align_off_in (stack_align_off_in)
+{
+ memset (m_regs, 0, sizeof (m_regs));
+ memset (m_syms, 0, sizeof (m_syms));
+ memset (m_stub_names, 0, sizeof (m_stub_names));
+
+ HOST_WIDE_INT offset = stack_align_off_in;
+ unsigned i, j;
+ for (i = j = 0; i < MAX_REGS; ++i)
+ {
+ unsigned regno = REG_ORDER[i];
+
+ if (regno == BP_REG && hfp)
+ continue;
+ if (SSE_REGNO_P (regno))
+ {
+ offset += 16;
+ /* Verify that SSE regs are always aligned. */
+ gcc_assert (!((stack_align_off_in + offset) & 15));
+ }
+ else
+ offset += 8;
+
+ m_regs[j].regno = regno;
+ m_regs[j++].offset = offset - STUB_INDEX_OFFSET;
+ }
+ gcc_assert (j == m_nregs);
+}
+
+/* Return rtx of a symbol ref for the entry point (based upon
+ cfun->machine->outline_ms_sysv_extra_regs) of the specified stub. */
+rtx xlogue_layout::get_stub_rtx (enum xlogue_stub stub) const
+{
+ const unsigned n_extra_regs = cfun->machine->outline_ms_sysv_extra_regs;
+ gcc_assert (n_extra_regs <= MAX_EXTRA_REGS);
+ gcc_assert (stub < XLOGUE_STUB_COUNT);
+
+ gcc_assert (crtl->stack_realign_finalized);
+
+ /* FIXME: For some reason, cached symbols go bad, so disable it for now.
+ Should we just remove the rtx cache or do we need to reset it at some
+ point? */
+ if (true || !m_syms[stub][n_extra_regs])
+ {
+ xlogue_layout *writey_this = const_cast<xlogue_layout*>(this);
+ char *stub_name = writey_this->m_stub_names[stub][n_extra_regs];
+ rtx sym;
+ int res;
+
+ res = snprintf (stub_name, STUB_NAME_MAX_LEN - 1, "__%s_%u",
+ STUB_BASE_NAMES[stub], 12 + n_extra_regs);
+ gcc_assert (res <= (int)STUB_NAME_MAX_LEN);
+
+ sym = gen_rtx_SYMBOL_REF (Pmode, stub_name);
+ writey_this->m_syms[stub][n_extra_regs] = sym;
+ }
+
+ gcc_assert (m_syms[stub][n_extra_regs]);
+ return m_syms[stub][n_extra_regs];
+}
+
/* Define the structure for the machine field in struct function. */
struct GTY(()) stack_local_entry {
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index ed7e4edec56..a79237dbdf0 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2577,6 +2577,24 @@ struct GTY(()) machine_function {
pass arguments and can be used for indirect sibcall. */
BOOL_BITFIELD arg_reg_available : 1;
+ /* If true, we're out-of-lining reg save/restore for regs clobbered
+ by ms_abi functions calling a sysv function. */
+ BOOL_BITFIELD outline_ms_sysv : 1;
+
+ /* If true, the incoming 16-byte aligned stack has an offset (of 8) and
+ needs padding. */
+ BOOL_BITFIELD outline_ms_sysv_pad_in : 1;
+
+ /* If true, the size of the stub save area plus inline int reg saves will
+ result in an 8 byte offset, so needs padding. */
+ BOOL_BITFIELD outline_ms_sysv_pad_out : 1;
+
+ /* This is the number of extra registers saved by stub (valid range is
+ 0-6). Each additional register is only saved/restored by the stubs
+ if all successive ones are. (Will always be zero when using a hard
+ frame pointer.) */
+ unsigned int outline_ms_sysv_extra_regs:3;
+
/* During prologue/epilogue generation, the current frame state.
Otherwise, the frame state at the end of the prologue. */
struct machine_frame_state fs;
--
2.11.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
2017-02-07 18:36 ` [PATCH 4/8] [i386] Modify ix86_save_reg to optionally omit stub-managed registers Daniel Santos
@ 2017-02-07 18:36 ` Daniel Santos
2017-02-08 23:28 ` Bernhard Reutner-Fischer
2017-02-07 18:36 ` [PATCH 3/8] [i386] Adds class xlouge_layout and new fields to struct machine_function Daniel Santos
` (5 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: Daniel Santos @ 2017-02-07 18:36 UTC (permalink / raw)
To: gcc-patches, Uros Bizjak, Jan Hubicka; +Cc: Sandra Loosemore
Adds the option to i386.opt and i386.c and adds documentation to
invoke.texi.
Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
gcc/config/i386/i386.c | 3 ++-
gcc/config/i386/i386.opt | 5 +++++
gcc/doc/invoke.texi | 11 ++++++++++-
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 05974208a27..9a0dfdc77ba 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -4361,7 +4361,8 @@ ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2,
{ "-mstv", MASK_STV },
{ "-mavx256-split-unaligned-load", MASK_AVX256_SPLIT_UNALIGNED_LOAD },
{ "-mavx256-split-unaligned-store", MASK_AVX256_SPLIT_UNALIGNED_STORE },
- { "-mprefer-avx128", MASK_PREFER_AVX128 }
+ { "-mprefer-avx128", MASK_PREFER_AVX128 },
+ { "-mmoutline-msabi-xlogues", MASK_OUTLINE_MSABI_XLOGUES }
};
/* Additional flag options. */
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 0ee31845eba..0ff93f831c0 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -538,6 +538,11 @@ Enum(calling_abi) String(sysv) Value(SYSV_ABI)
EnumValue
Enum(calling_abi) String(ms) Value(MS_ABI)
+moutline-msabi-xlogues
+Target Report Mask(OUTLINE_MSABI_XLOGUES) Save
+Reduces function size by using out-of-line stubs to save & restore registers
+clobberd by differences in Microsoft and System V ABIs.
+
mveclibabi=
Target RejectNegative Joined Var(ix86_veclibabi_type) Enum(ix86_veclibabi) Init(ix86_veclibabi_type_none)
Vector library ABI to use.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4b13aeb7426..901abbf99d6 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1210,7 +1210,7 @@ See RS/6000 and PowerPC Options.
-msse2avx -mfentry -mrecord-mcount -mnop-mcount -m8bit-idiv @gol
-mavx256-split-unaligned-load -mavx256-split-unaligned-store @gol
-malign-data=@var{type} -mstack-protector-guard=@var{guard} @gol
--mmitigate-rop -mgeneral-regs-only}
+-mmitigate-rop -mgeneral-regs-only -moutline-msabi-xlogues}
@emph{x86 Windows Options}
@gccoptlist{-mconsole -mcygwin -mno-cygwin -mdll @gol
@@ -25304,6 +25304,15 @@ You can control this behavior for specific functions by
using the function attributes @code{ms_abi} and @code{sysv_abi}.
@xref{Function Attributes}.
+@item -moutline-msabi-xlogues
+@opindex moutline-msabi-xlogues
+@opindex no-moutline-msabi-xlogues
+Due to differences in 64-bit ABIs, any Microsoft ABI function that calls a
+SysV ABI function must consider RSI, RDI and XMM6-15 as clobbered, emitting
+fairly lengthy prologues and epilogues. This option generates prologues and
+epilogues that instead call stubs in libgcc to perform these saves & restores,
+thus reducing function size at the cost of and few extra instructions.
+
@item -mtls-dialect=@var{type}
@opindex mtls-dialect
Generate code to access thread-local storage using the @samp{gnu} or
--
2.11.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 4/8] [i386] Modify ix86_save_reg to optionally omit stub-managed registers
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
@ 2017-02-07 18:36 ` Daniel Santos
2017-02-07 18:36 ` [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues Daniel Santos
` (6 subsequent siblings)
7 siblings, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-07 18:36 UTC (permalink / raw)
To: gcc-patches, Uros Bizjak, Jan Hubicka
Adds HARD_REG_SET stub_managed_regs to track registers that will be
managed by the pro/epilogue stubs for the function.
Adds a third parameter bool ignore_outlined to ix86_save_reg to specify
rather or not the count should include registers marked in
stub_managed_regs.
Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
gcc/config/i386/i386.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 6449fbb42bb..d52533103f5 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -12463,6 +12463,10 @@ ix86_hard_regno_scratch_ok (unsigned int regno)
&& df_regs_ever_live_p (regno)));
}
+/* Registers who's save & restore will be managed by stubs called from
+ pro/epilogue. */
+static HARD_REG_SET GTY(()) stub_managed_regs;
+
/* Return true if register class CL should be an additional allocno
class. */
@@ -12475,7 +12479,7 @@ ix86_additional_allocno_class_p (reg_class_t cl)
/* Return TRUE if we need to save REGNO. */
static bool
-ix86_save_reg (unsigned int regno, bool maybe_eh_return)
+ix86_save_reg (unsigned int regno, bool maybe_eh_return, bool ignore_outlined)
{
/* If there are no caller-saved registers, we preserve all registers,
except for MMX and x87 registers which aren't supported when saving
@@ -12543,6 +12547,10 @@ ix86_save_reg (unsigned int regno, bool maybe_eh_return)
}
}
+ if (ignore_outlined && cfun->machine->outline_ms_sysv
+ && in_hard_reg_set_p (stub_managed_regs, DImode, regno))
+ return false;
+
if (crtl->drap_reg
&& regno == REGNO (crtl->drap_reg)
&& !cfun->machine->no_drap_save_restore)
@@ -12563,7 +12571,7 @@ ix86_nsaved_regs (void)
int regno;
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
- if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true))
+ if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
nregs ++;
return nregs;
}
@@ -12579,7 +12587,7 @@ ix86_nsaved_sseregs (void)
if (!TARGET_64BIT_MS_ABI)
return 0;
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
- if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
+ if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true))
nregs ++;
return nregs;
}
@@ -12659,6 +12667,7 @@ ix86_compute_frame_layout (struct ix86_frame *frame)
frame->nregs = ix86_nsaved_regs ();
frame->nsseregs = ix86_nsaved_sseregs ();
+ CLEAR_HARD_REG_SET (stub_managed_regs);
/* 64-bit MS ABI seem to require stack alignment to be always 16,
except for function prologues, leaf functions and when the defult
@@ -13049,7 +13058,7 @@ ix86_emit_save_regs (void)
rtx_insn *insn;
for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
- if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true))
+ if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
{
insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno)));
RTX_FRAME_RELATED_P (insn) = 1;
@@ -13139,7 +13148,7 @@ ix86_emit_save_regs_using_mov (HOST_WIDE_INT cfa_offset)
unsigned int regno;
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
- if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true))
+ if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true))
{
ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset);
cfa_offset -= UNITS_PER_WORD;
@@ -13154,7 +13163,7 @@ ix86_emit_save_sse_regs_using_mov (HOST_WIDE_INT cfa_offset)
unsigned int regno;
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
- if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
+ if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true, true))
{
ix86_emit_save_reg_using_mov (V4SFmode, regno, cfa_offset);
cfa_offset -= GET_MODE_SIZE (V4SFmode);
@@ -13538,13 +13547,13 @@ get_scratch_register_on_entry (struct scratch_reg *sr)
&& !static_chain_p
&& drap_regno != CX_REG)
regno = CX_REG;
- else if (ix86_save_reg (BX_REG, true))
+ else if (ix86_save_reg (BX_REG, true, false))
regno = BX_REG;
/* esi is the static chain register. */
else if (!(regparm == 3 && static_chain_p)
- && ix86_save_reg (SI_REG, true))
+ && ix86_save_reg (SI_REG, true, false))
regno = SI_REG;
- else if (ix86_save_reg (DI_REG, true))
+ else if (ix86_save_reg (DI_REG, true, false))
regno = DI_REG;
else
{
@@ -14648,7 +14657,7 @@ ix86_emit_restore_regs_using_mov (HOST_WIDE_INT cfa_offset,
unsigned int regno;
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
- if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
+ if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true))
{
rtx reg = gen_rtx_REG (word_mode, regno);
rtx mem;
@@ -14687,7 +14696,7 @@ ix86_emit_restore_sse_regs_using_mov (HOST_WIDE_INT cfa_offset,
unsigned int regno;
for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
- if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
+ if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return, true))
{
rtx reg = gen_rtx_REG (V4SFmode, regno);
rtx mem;
--
2.11.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 5/8] [i386] Modify ix86_compute_frame_layout for foutline-msabi-xlogues
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
` (5 preceding siblings ...)
2017-02-07 18:37 ` [PATCH 6/8] [i386] Add patterns and predicates foutline-msabi-xlouges Daniel Santos
@ 2017-02-07 18:37 ` Daniel Santos
2017-02-10 10:32 ` [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Uros Bizjak
7 siblings, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-07 18:37 UTC (permalink / raw)
To: gcc-patches, Uros Bizjak, Jan Hubicka
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 <daniel.santos@pobox.com>
---
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
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 7/8] [i386] Add msabi pro/epilogue stubs to libgcc
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
` (2 preceding siblings ...)
2017-02-07 18:36 ` [PATCH 3/8] [i386] Adds class xlouge_layout and new fields to struct machine_function Daniel Santos
@ 2017-02-07 18:37 ` Daniel Santos
2017-02-07 18:37 ` [PATCH 1/8] [i386] Minor refactoring Daniel Santos
` (3 subsequent siblings)
7 siblings, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-07 18:37 UTC (permalink / raw)
To: gcc-patches, Uros Bizjak, Jan Hubicka
Adds libgcc/config/i386/i386-asm.h to manage common cpp and gas macros.
stubs use the following naming convention:
(sav|res)ms64[f][x]
save|res Save or restore
ms64 Avoid possible name collisions with future stubs
(specific to 64-bit msabi --> sysv scenario)
[f] Variant for hard frame pointer (and stack realignment)
[x] Tail-call variant (is the return from function)
Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
libgcc/config.host | 2 +-
libgcc/config/i386/i386-asm.h | 82 ++++++++++++++++++++++++++++++++++++++++++
libgcc/config/i386/resms64.S | 57 +++++++++++++++++++++++++++++
libgcc/config/i386/resms64f.S | 55 ++++++++++++++++++++++++++++
libgcc/config/i386/resms64fx.S | 57 +++++++++++++++++++++++++++++
libgcc/config/i386/resms64x.S | 59 ++++++++++++++++++++++++++++++
libgcc/config/i386/savms64.S | 57 +++++++++++++++++++++++++++++
libgcc/config/i386/savms64f.S | 55 ++++++++++++++++++++++++++++
libgcc/config/i386/t-msabi | 7 ++++
9 files changed, 430 insertions(+), 1 deletion(-)
create mode 100644 libgcc/config/i386/i386-asm.h
create mode 100644 libgcc/config/i386/resms64.S
create mode 100644 libgcc/config/i386/resms64f.S
create mode 100644 libgcc/config/i386/resms64fx.S
create mode 100644 libgcc/config/i386/resms64x.S
create mode 100644 libgcc/config/i386/savms64.S
create mode 100644 libgcc/config/i386/savms64f.S
create mode 100644 libgcc/config/i386/t-msabi
diff --git a/libgcc/config.host b/libgcc/config.host
index 540bfa96358..6c497b13a27 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1339,7 +1339,7 @@ case ${host} in
i[34567]86-*-linux* | x86_64-*-linux* | \
i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu | \
i[34567]86-*-gnu*)
- tmake_file="${tmake_file} t-tls i386/t-linux t-slibgcc-libgcc"
+ tmake_file="${tmake_file} t-tls i386/t-linux i386/t-msabi t-slibgcc-libgcc"
if test "$libgcc_cv_cfi" = "yes"; then
tmake_file="${tmake_file} t-stack i386/t-stack-i386"
fi
diff --git a/libgcc/config/i386/i386-asm.h b/libgcc/config/i386/i386-asm.h
new file mode 100644
index 00000000000..c613e9fd83d
--- /dev/null
+++ b/libgcc/config/i386/i386-asm.h
@@ -0,0 +1,82 @@
+/* Defines common perprocessor and assembly macros for use by various stubs.
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ Contributed by Daniel Santos <daniel.santos@pobox.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifndef I386_ASM_H
+#define I386_ASM_H
+
+#ifdef __ELF__
+# define ELFFN(fn) .type fn,@function
+#else
+# define ELFFN(fn)
+#endif
+
+#define FUNC_START(fn) \
+ .global fn; \
+ ELFFN (fn); \
+fn:
+
+#define HIDDEN_FUNC(fn)\
+ FUNC_START (fn) \
+ .hidden fn; \
+
+#define FUNC_END(fn) .size fn,.-fn
+
+#ifdef __SSE2__
+# ifdef __AVX__
+# define MOVAPS vmovaps
+# else
+# define MOVAPS movaps
+# endif
+
+/* Save SSE registers 6-15. off is the offset of rax to get to xmm6. */
+.macro SSE_SAVE off=0
+ MOVAPS %xmm15,(\off - 0x90)(%rax)
+ MOVAPS %xmm14,(\off - 0x80)(%rax)
+ MOVAPS %xmm13,(\off - 0x70)(%rax)
+ MOVAPS %xmm12,(\off - 0x60)(%rax)
+ MOVAPS %xmm11,(\off - 0x50)(%rax)
+ MOVAPS %xmm10,(\off - 0x40)(%rax)
+ MOVAPS %xmm9, (\off - 0x30)(%rax)
+ MOVAPS %xmm8, (\off - 0x20)(%rax)
+ MOVAPS %xmm7, (\off - 0x10)(%rax)
+ MOVAPS %xmm6, \off(%rax)
+.endm
+
+/* Restore SSE registers 6-15. off is the offset of rsi to get to xmm6. */
+.macro SSE_RESTORE off=0
+ MOVAPS (\off - 0x90)(%rsi), %xmm15
+ MOVAPS (\off - 0x80)(%rsi), %xmm14
+ MOVAPS (\off - 0x70)(%rsi), %xmm13
+ MOVAPS (\off - 0x60)(%rsi), %xmm12
+ MOVAPS (\off - 0x50)(%rsi), %xmm11
+ MOVAPS (\off - 0x40)(%rsi), %xmm10
+ MOVAPS (\off - 0x30)(%rsi), %xmm9
+ MOVAPS (\off - 0x20)(%rsi), %xmm8
+ MOVAPS (\off - 0x10)(%rsi), %xmm7
+ MOVAPS \off(%rsi), %xmm6
+.endm
+
+#endif /* __SSE2__ */
+#endif /* I386_ASM_H */
diff --git a/libgcc/config/i386/resms64.S b/libgcc/config/i386/resms64.S
new file mode 100644
index 00000000000..f47e2f066fb
--- /dev/null
+++ b/libgcc/config/i386/resms64.S
@@ -0,0 +1,57 @@
+/* Epilogue stub for 64-bit ms/sysv clobbers: restore
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ Contributed by Daniel Santos <daniel.santos@pobox.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifdef __x86_64__
+#include "i386-asm.h"
+
+/* Epilogue routine for restoring 64-bit ms/sysv registers. */
+
+ .text
+HIDDEN_FUNC(__resms64_18)
+ mov -0x70(%rsi),%r15
+HIDDEN_FUNC(__resms64_17)
+ mov -0x68(%rsi),%r14
+HIDDEN_FUNC(__resms64_16)
+ mov -0x60(%rsi),%r13
+HIDDEN_FUNC(__resms64_15)
+ mov -0x58(%rsi),%r12
+HIDDEN_FUNC(__resms64_14)
+ mov -0x50(%rsi),%rbp
+HIDDEN_FUNC(__resms64_13)
+ mov -0x48(%rsi),%rbx
+HIDDEN_FUNC(__resms64_12)
+ mov -0x40(%rsi),%rdi
+ SSE_RESTORE off=0x60
+ mov -0x38(%rsi),%rsi
+ ret
+FUNC_END(__resms64_12)
+FUNC_END(__resms64_13)
+FUNC_END(__resms64_14)
+FUNC_END(__resms64_15)
+FUNC_END(__resms64_16)
+FUNC_END(__resms64_17)
+FUNC_END(__resms64_18)
+
+#endif /* __x86_64__ */
diff --git a/libgcc/config/i386/resms64f.S b/libgcc/config/i386/resms64f.S
new file mode 100644
index 00000000000..817da60cf15
--- /dev/null
+++ b/libgcc/config/i386/resms64f.S
@@ -0,0 +1,55 @@
+/* Epilogue stub for 64-bit ms/sysv clobbers: restore (with hard frame pointer)
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ Contributed by Daniel Santos <daniel.santos@pobox.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifdef __x86_64__
+#include "i386-asm.h"
+
+/* Epilogue routine for restoring 64-bit ms/sysv registers when hard frame
+ pointer is used. */
+
+ .text
+HIDDEN_FUNC(__resms64f_17)
+ mov -0x68(%rsi),%r15
+HIDDEN_FUNC(__resms64f_16)
+ mov -0x60(%rsi),%r14
+HIDDEN_FUNC(__resms64f_15)
+ mov -0x58(%rsi),%r13
+HIDDEN_FUNC(__resms64f_14)
+ mov -0x50(%rsi),%r12
+HIDDEN_FUNC(__resms64f_13)
+ mov -0x48(%rsi),%rbx
+HIDDEN_FUNC(__resms64f_12)
+ mov -0x40(%rsi),%rdi
+ SSE_RESTORE off=0x60
+ mov -0x38(%rsi),%rsi
+ ret
+FUNC_END(__resms64f_12)
+FUNC_END(__resms64f_13)
+FUNC_END(__resms64f_14)
+FUNC_END(__resms64f_15)
+FUNC_END(__resms64f_16)
+FUNC_END(__resms64f_17)
+
+#endif /* __x86_64__ */
diff --git a/libgcc/config/i386/resms64fx.S b/libgcc/config/i386/resms64fx.S
new file mode 100644
index 00000000000..5dba5848dee
--- /dev/null
+++ b/libgcc/config/i386/resms64fx.S
@@ -0,0 +1,57 @@
+/* Epilogue stub for 64-bit ms/sysv clobbers: restore, leave and return
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ Contributed by Daniel Santos <daniel.santos@pobox.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifdef __x86_64__
+#include "i386-asm.h"
+
+/* Epilogue routine for 64-bit ms/sysv registers when hard frame pointer
+ * used -- restores registers, restores frame pointer and then returns
+ * from the function. */
+
+ .text
+HIDDEN_FUNC(__resms64fx_17)
+ mov -0x68(%rsi),%r15
+HIDDEN_FUNC(__resms64fx_16)
+ mov -0x60(%rsi),%r14
+HIDDEN_FUNC(__resms64fx_15)
+ mov -0x58(%rsi),%r13
+HIDDEN_FUNC(__resms64fx_14)
+ mov -0x50(%rsi),%r12
+HIDDEN_FUNC(__resms64fx_13)
+ mov -0x48(%rsi),%rbx
+HIDDEN_FUNC(__resms64fx_12)
+ mov -0x40(%rsi),%rdi
+ SSE_RESTORE off=0x60
+ mov -0x38(%rsi),%rsi
+ leaveq
+ ret
+FUNC_END(__resms64fx_12)
+FUNC_END(__resms64fx_13)
+FUNC_END(__resms64fx_14)
+FUNC_END(__resms64fx_15)
+FUNC_END(__resms64fx_16)
+FUNC_END(__resms64fx_17)
+
+#endif /* __x86_64__ */
diff --git a/libgcc/config/i386/resms64x.S b/libgcc/config/i386/resms64x.S
new file mode 100644
index 00000000000..7770447cf38
--- /dev/null
+++ b/libgcc/config/i386/resms64x.S
@@ -0,0 +1,59 @@
+/* Epilogue stub for 64-bit ms/sysv clobbers: restore and return
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ Contributed by Daniel Santos <daniel.santos@pobox.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifdef __x86_64__
+#include "i386-asm.h"
+
+/* Epilogue routine for restoring 64-bit ms/sysv registers and returning from
+ * function. */
+
+ .text
+HIDDEN_FUNC(__resms64x_18)
+ mov -0x70(%rsi),%r15
+HIDDEN_FUNC(__resms64x_17)
+ mov -0x68(%rsi),%r14
+HIDDEN_FUNC(__resms64x_16)
+ mov -0x60(%rsi),%r13
+HIDDEN_FUNC(__resms64x_15)
+ mov -0x58(%rsi),%r12
+HIDDEN_FUNC(__resms64x_14)
+ mov -0x50(%rsi),%rbp
+HIDDEN_FUNC(__resms64x_13)
+ mov -0x48(%rsi),%rbx
+HIDDEN_FUNC(__resms64x_12)
+ mov -0x40(%rsi),%rdi
+ SSE_RESTORE off=0x60
+ mov -0x38(%rsi),%rsi
+ mov %r10,%rsp
+ ret
+FUNC_END(__resms64x_12)
+FUNC_END(__resms64x_13)
+FUNC_END(__resms64x_14)
+FUNC_END(__resms64x_15)
+FUNC_END(__resms64x_16)
+FUNC_END(__resms64x_17)
+FUNC_END(__resms64x_18)
+
+#endif /* __x86_64__ */
diff --git a/libgcc/config/i386/savms64.S b/libgcc/config/i386/savms64.S
new file mode 100644
index 00000000000..2067dd8614f
--- /dev/null
+++ b/libgcc/config/i386/savms64.S
@@ -0,0 +1,57 @@
+/* Prologue stub for 64-bit ms/sysv clobbers: save
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ Contributed by Daniel Santos <daniel.santos@pobox.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifdef __x86_64__
+#include "i386-asm.h"
+
+/* Prologue routine for saving 64-bit ms/sysv registers. */
+
+ .text
+HIDDEN_FUNC(__savms64_18)
+ mov %r15,-0x70(%rax)
+HIDDEN_FUNC(__savms64_17)
+ mov %r14,-0x68(%rax)
+HIDDEN_FUNC(__savms64_16)
+ mov %r13,-0x60(%rax)
+HIDDEN_FUNC(__savms64_15)
+ mov %r12,-0x58(%rax)
+HIDDEN_FUNC(__savms64_14)
+ mov %rbp,-0x50(%rax)
+HIDDEN_FUNC(__savms64_13)
+ mov %rbx,-0x48(%rax)
+HIDDEN_FUNC(__savms64_12)
+ mov %rdi,-0x40(%rax)
+ mov %rsi,-0x38(%rax)
+ SSE_SAVE off=0x60
+ ret
+FUNC_END(__savms64_12)
+FUNC_END(__savms64_13)
+FUNC_END(__savms64_14)
+FUNC_END(__savms64_15)
+FUNC_END(__savms64_16)
+FUNC_END(__savms64_17)
+FUNC_END(__savms64_18)
+
+#endif /* __x86_64__ */
diff --git a/libgcc/config/i386/savms64f.S b/libgcc/config/i386/savms64f.S
new file mode 100644
index 00000000000..81583b6eb68
--- /dev/null
+++ b/libgcc/config/i386/savms64f.S
@@ -0,0 +1,55 @@
+/* Prologue stub for 64-bit ms/sysv clobbers: save (with hard frame pointer)
+ Copyright (C) 2016-2017 Free Software Foundation, Inc.
+ Contributed by Daniel Santos <daniel.santos@pobox.com>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifdef __x86_64__
+#include "i386-asm.h"
+
+/* Prologue routine for saving 64-bit ms/sysv registers when realignment is
+ * needed or hard frame pointer used. */
+
+ .text
+HIDDEN_FUNC(__savms64f_17)
+ mov %r15,-0x68(%rax)
+HIDDEN_FUNC(__savms64f_16)
+ mov %r14,-0x60(%rax)
+HIDDEN_FUNC(__savms64f_15)
+ mov %r13,-0x58(%rax)
+HIDDEN_FUNC(__savms64f_14)
+ mov %r12,-0x50(%rax)
+HIDDEN_FUNC(__savms64f_13)
+ mov %rbx,-0x48(%rax)
+HIDDEN_FUNC(__savms64f_12)
+ mov %rdi,-0x40(%rax)
+ mov %rsi,-0x38(%rax)
+ SSE_SAVE off=0x60
+ ret
+FUNC_END(__savms64f_12)
+FUNC_END(__savms64f_13)
+FUNC_END(__savms64f_14)
+FUNC_END(__savms64f_15)
+FUNC_END(__savms64f_16)
+FUNC_END(__savms64f_17)
+
+#endif /* __x86_64__ */
diff --git a/libgcc/config/i386/t-msabi b/libgcc/config/i386/t-msabi
new file mode 100644
index 00000000000..dbb0fa0a697
--- /dev/null
+++ b/libgcc/config/i386/t-msabi
@@ -0,0 +1,7 @@
+# Makefile fragment to support -foutline-msabi-xlogue
+LIB2ADD_ST += $(srcdir)/config/i386/savms64.S \
+ $(srcdir)/config/i386/resms64.S \
+ $(srcdir)/config/i386/resms64x.S \
+ $(srcdir)/config/i386/savms64f.S \
+ $(srcdir)/config/i386/resms64f.S \
+ $(srcdir)/config/i386/resms64fx.S
--
2.11.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 6/8] [i386] Add patterns and predicates foutline-msabi-xlouges
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
` (4 preceding siblings ...)
2017-02-07 18:37 ` [PATCH 1/8] [i386] Minor refactoring Daniel Santos
@ 2017-02-07 18:37 ` Daniel Santos
2017-02-07 18:37 ` [PATCH 5/8] [i386] Modify ix86_compute_frame_layout for foutline-msabi-xlogues Daniel Santos
2017-02-10 10:32 ` [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Uros Bizjak
7 siblings, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-07 18:37 UTC (permalink / raw)
To: gcc-patches, Uros Bizjak, Jan Hubicka
Adds the predicates save_multiple and restore_multiple to predicates.md,
which are used by following patterns in sse.md:
* save_multiple - insn that calls a save stub
* restore_multiple - call_insn that calls a save stub and returns to the
function to allow a sibling call (which should typically offer better
optimization than the restore stub as the tail call)
* restore_multiple_and_return - a jump_insn that returns from the
function as a tail-call.
* restore_multiple_leave_return - like the above, but restores the frame
pointer before returning.
Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
gcc/config/i386/predicates.md | 155 ++++++++++++++++++++++++++++++++++++++++++
gcc/config/i386/sse.md | 37 ++++++++++
2 files changed, 192 insertions(+)
diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md
index 8f250a2e720..36fe8abc3f4 100644
--- a/gcc/config/i386/predicates.md
+++ b/gcc/config/i386/predicates.md
@@ -1657,3 +1657,158 @@
(ior (match_operand 0 "register_operand")
(and (match_code "const_int")
(match_test "op == constm1_rtx"))))
+
+;; Return true if:
+;; 1. first op is a symbol reference,
+;; 2. >= 13 operands, and
+;; 3. operands 2 to end is one of:
+;; a. save a register to a memory location, or
+;; b. restore stack pointer.
+(define_predicate "save_multiple"
+ (match_code "parallel")
+{
+ const unsigned nregs = XVECLEN (op, 0);
+ rtx head = XVECEXP (op, 0, 0);
+ unsigned i;
+
+ if (GET_CODE (head) != USE)
+ return false;
+ else
+ {
+ rtx op0 = XEXP (head, 0);
+ if (op0 == NULL_RTX || GET_CODE (op0) != SYMBOL_REF)
+ return false;
+ }
+
+ if (nregs < 13)
+ return false;
+
+ for (i = 2; i < nregs; i++)
+ {
+ rtx e, src, dest;
+
+ e = XVECEXP (op, 0, i);
+
+ switch (GET_CODE (e))
+ {
+ case SET:
+ src = SET_SRC (e);
+ dest = SET_DEST (e);
+
+ /* storing a register to memory. */
+ if (GET_CODE (src) == REG && GET_CODE (dest) == MEM)
+ {
+ rtx addr = XEXP (dest, 0);
+
+ /* Good if dest address is in RAX. */
+ if (GET_CODE (addr) == REG
+ && REGNO (addr) == AX_REG)
+ continue;
+
+ /* Good if dest address is offset of RAX. */
+ if (GET_CODE (addr) == PLUS
+ && GET_CODE (XEXP (addr, 0)) == REG
+ && REGNO (XEXP (addr, 0)) == AX_REG)
+ continue;
+ }
+ break;
+
+ default:
+ break;
+ }
+ return false;
+ }
+ return true;
+})
+
+;; Return true if:
+;; * first op is (return) or a a use (symbol reference),
+;; * >= 14 operands, and
+;; * operands 2 to end are one of:
+;; - restoring a register from a memory location that's an offset of RSI.
+;; - clobbering a reg
+;; - adjusting SP
+(define_predicate "restore_multiple"
+ (match_code "parallel")
+{
+ const unsigned nregs = XVECLEN (op, 0);
+ rtx head = XVECEXP (op, 0, 0);
+ unsigned i;
+
+ switch (GET_CODE (head))
+ {
+ case RETURN:
+ i = 3;
+ break;
+
+ case USE:
+ {
+ rtx op0 = XEXP (head, 0);
+
+ if (op0 == NULL_RTX || GET_CODE (op0) != SYMBOL_REF)
+ return false;
+
+ i = 1;
+ break;
+ }
+
+ default:
+ return false;
+ }
+
+ if (nregs < i + 12)
+ return false;
+
+ for (; i < nregs; i++)
+ {
+ rtx e, src, dest;
+
+ e = XVECEXP (op, 0, i);
+
+ switch (GET_CODE (e))
+ {
+ case CLOBBER:
+ continue;
+
+ case SET:
+ src = SET_SRC (e);
+ dest = SET_DEST (e);
+
+ /* Restoring a register from memory. */
+ if (GET_CODE (src) == MEM && GET_CODE (dest) == REG)
+ {
+ rtx addr = XEXP (src, 0);
+
+ /* Good if src address is in RSI. */
+ if (GET_CODE (addr) == REG
+ && REGNO (addr) == SI_REG)
+ continue;
+
+ /* Good if src address is offset of RSI. */
+ if (GET_CODE (addr) == PLUS
+ && GET_CODE (XEXP (addr, 0)) == REG
+ && REGNO (XEXP (addr, 0)) == SI_REG)
+ continue;
+
+ /* Good if adjusting stack pointer. */
+ if (GET_CODE (dest) == REG
+ && REGNO (dest) == SP_REG
+ && GET_CODE (src) == PLUS
+ && GET_CODE (XEXP (src, 0)) == REG
+ && REGNO (XEXP (src, 0)) == SP_REG)
+ continue;
+ }
+
+ /* Restoring stack pointer from another register. */
+ if (GET_CODE (dest) == REG && REGNO (dest) == SP_REG
+ && GET_CODE (src) == REG)
+ continue;
+ break;
+
+ default:
+ break;
+ }
+ return false;
+ }
+ return true;
+})
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index a19c8f2bc2e..b9db729c427 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -19885,3 +19885,40 @@
(match_operand:VI48_512 1 "nonimmediate_operand" "vm")))]
"TARGET_AVX512VPOPCNTDQ"
"vpopcnt<ssemodesuffix>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}")
+
+;; Save multiple registers out-of-line.
+(define_insn "save_multiple<mode>"
+ [(match_parallel 0 "save_multiple"
+ [(use (match_operand:P 1 "symbol_operand"))
+ (const_int 0)
+ ])]
+ "TARGET_SSE && TARGET_64BIT"
+ "call\t%P1")
+
+;; Restore multiple registers out-of-line.
+(define_insn "restore_multiple<mode>"
+ [(match_parallel 0 "restore_multiple"
+ [(use (match_operand:P 1 "symbol_operand"))])]
+ "TARGET_SSE && TARGET_64BIT"
+ "call\t%P1")
+
+;; Restore multiple registers out-of-line and return.
+(define_insn "restore_multiple_and_return<mode>"
+ [(match_parallel 0 "restore_multiple"
+ [(return)
+ (use (match_operand:P 1 "symbol_operand"))
+ (const_int 0)
+ ])]
+ "TARGET_SSE && TARGET_64BIT"
+ "jmp\t%P1")
+
+;; Restore multiple registers out-of-line when hard frame pointer is used,
+;; perform the leave operation prior to returning (from the function).
+(define_insn "restore_multiple_leave_return<mode>"
+ [(match_parallel 0 "restore_multiple"
+ [(return)
+ (use (match_operand:P 1 "symbol_operand"))
+ (const_int 1)
+ ])]
+ "TARGET_SSE && TARGET_64BIT"
+ "jmp\t%P1")
--
2.11.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 1/8] [i386] Minor refactoring
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
` (3 preceding siblings ...)
2017-02-07 18:37 ` [PATCH 7/8] [i386] Add msabi pro/epilogue stubs to libgcc Daniel Santos
@ 2017-02-07 18:37 ` Daniel Santos
2017-02-07 18:37 ` [PATCH 6/8] [i386] Add patterns and predicates foutline-msabi-xlouges Daniel Santos
` (2 subsequent siblings)
7 siblings, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-07 18:37 UTC (permalink / raw)
To: gcc-patches, Uros Bizjak, Jan Hubicka
For the sake of clarity, I've separated out these minor refactoring
changes from the rest of the patches.
Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
---
gcc/config/i386/i386.c | 21 ++++++++++-----------
gcc/config/i386/i386.h | 4 +++-
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index abc0136f78e..05974208a27 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -2422,7 +2422,7 @@ static int const x86_64_int_return_registers[4] =
/* Additional registers that are clobbered by SYSV calls. */
-int const x86_64_ms_sysv_extra_clobbered_registers[12] =
+unsigned const x86_64_ms_sysv_extra_clobbered_registers[12] =
{
SI_REG, DI_REG,
XMM6_REG, XMM7_REG,
@@ -12388,6 +12388,7 @@ ix86_builtin_setjmp_frame_value (void)
static void
ix86_compute_frame_layout (struct ix86_frame *frame)
{
+ struct machine_function *m = cfun->machine;
unsigned HOST_WIDE_INT stack_alignment_needed;
HOST_WIDE_INT offset;
unsigned HOST_WIDE_INT preferred_alignment;
@@ -12422,19 +12423,19 @@ ix86_compute_frame_layout (struct ix86_frame *frame)
scheduling that can be done, which means that there's very little point
in doing anything except PUSHs. */
if (TARGET_SEH)
- cfun->machine->use_fast_prologue_epilogue = false;
+ m->use_fast_prologue_epilogue = false;
/* During reload iteration the amount of registers saved can change.
Recompute the value as needed. Do not recompute when amount of registers
didn't change as reload does multiple calls to the function and does not
expect the decision to change within single iteration. */
else if (!optimize_bb_for_size_p (ENTRY_BLOCK_PTR_FOR_FN (cfun))
- && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
+ && m->use_fast_prologue_epilogue_nregs != frame->nregs)
{
int count = frame->nregs;
struct cgraph_node *node = cgraph_node::get (current_function_decl);
- cfun->machine->use_fast_prologue_epilogue_nregs = count;
+ m->use_fast_prologue_epilogue_nregs = count;
/* The fast prologue uses move instead of push to save registers. This
is significantly longer, but also executes faster as modern hardware
@@ -12451,14 +12452,14 @@ ix86_compute_frame_layout (struct ix86_frame *frame)
if (node->frequency < NODE_FREQUENCY_NORMAL
|| (flag_branch_probabilities
&& node->frequency < NODE_FREQUENCY_HOT))
- cfun->machine->use_fast_prologue_epilogue = false;
+ m->use_fast_prologue_epilogue = false;
else
- cfun->machine->use_fast_prologue_epilogue
+ m->use_fast_prologue_epilogue
= !expensive_function_p (count);
}
frame->save_regs_using_mov
- = (TARGET_PROLOGUE_USING_MOVE && cfun->machine->use_fast_prologue_epilogue
+ = (TARGET_PROLOGUE_USING_MOVE && m->use_fast_prologue_epilogue
/* If static stack checking is enabled and done with probes,
the registers need to be saved before allocating the frame. */
&& flag_stack_check != STATIC_BUILTIN_STACK_CHECK);
@@ -28479,11 +28480,9 @@ ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
else if (TARGET_64BIT_MS_ABI
&& (!callarg2 || INTVAL (callarg2) != -2))
{
- int const cregs_size
- = ARRAY_SIZE (x86_64_ms_sysv_extra_clobbered_registers);
- int i;
+ unsigned i;
- for (i = 0; i < cregs_size; i++)
+ for (i = 0; i < NUM_X86_64_MS_CLOBBERED_REGS; i++)
{
int regno = x86_64_ms_sysv_extra_clobbered_registers[i];
machine_mode mode = SSE_REGNO_P (regno) ? TImode : DImode;
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index a5cd8452424..ed7e4edec56 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2162,7 +2162,9 @@ extern int const dbx_register_map[FIRST_PSEUDO_REGISTER];
extern int const dbx64_register_map[FIRST_PSEUDO_REGISTER];
extern int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER];
-extern int const x86_64_ms_sysv_extra_clobbered_registers[12];
+extern unsigned const x86_64_ms_sysv_extra_clobbered_registers[12];
+#define NUM_X86_64_MS_CLOBBERED_REGS \
+ (ARRAY_SIZE (x86_64_ms_sysv_extra_clobbered_registers))
/* Before the prologue, RA is at 0(%esp). */
#define INCOMING_RETURN_ADDR_RTX \
--
2.11.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues
2017-02-07 18:36 ` [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues Daniel Santos
@ 2017-02-08 23:28 ` Bernhard Reutner-Fischer
2017-02-10 4:43 ` Daniel Santos
0 siblings, 1 reply; 23+ messages in thread
From: Bernhard Reutner-Fischer @ 2017-02-08 23:28 UTC (permalink / raw)
To: gcc-patches, Daniel Santos, Uros Bizjak, Jan Hubicka; +Cc: Sandra Loosemore
On 7 February 2017 19:40:17 CET, Daniel Santos <daniel.santos@pobox.com> wrote:
>+ { "-mmoutline-msabi-xlogues", MASK_OUTLINE_MSABI_XLOGUES }
> };
s/mm/m/
>+thus reducing function size at the cost of and few extra instructions.
s/and/a/
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues
2017-02-08 23:28 ` Bernhard Reutner-Fischer
@ 2017-02-10 4:43 ` Daniel Santos
2017-02-10 16:54 ` Sandra Loosemore
0 siblings, 1 reply; 23+ messages in thread
From: Daniel Santos @ 2017-02-10 4:43 UTC (permalink / raw)
To: Bernhard Reutner-Fischer, gcc-patches; +Cc: Sandra Loosemore
On 02/08/2017 05:28 PM, Bernhard Reutner-Fischer wrote:
> On 7 February 2017 19:40:17 CET, Daniel Santos <daniel.santos@pobox.com> wrote:
>
>> + { "-mmoutline-msabi-xlogues", MASK_OUTLINE_MSABI_XLOGUES }
>> };
> s/mm/m/
>
>> +thus reducing function size at the cost of and few extra instructions.
> s/and/a/
>
Thanks for catching these. I have them corrected, but I'm going to wait
for feedback from the i386 guys before I post a revised patch set.
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
` (6 preceding siblings ...)
2017-02-07 18:37 ` [PATCH 5/8] [i386] Modify ix86_compute_frame_layout for foutline-msabi-xlogues Daniel Santos
@ 2017-02-10 10:32 ` Uros Bizjak
2017-02-10 11:34 ` JonY
2017-02-10 17:55 ` Daniel Santos
7 siblings, 2 replies; 23+ messages in thread
From: Uros Bizjak @ 2017-02-10 10:32 UTC (permalink / raw)
To: Daniel Santos; +Cc: gcc-patches, Jan Hubicka, Sandra Loosemore, 10walls
On Tue, Feb 7, 2017 at 7:38 PM, Daniel Santos <daniel.santos@pobox.com> wrote:
> Uros or Jan,
> Please take this as a ping, as I never bothered pinging after submitting v2
> since I found a few more issues with it. :) Although I realize this would be
> a GCC 8 stage 1 item, I would like to try to get it finished up and
> tentatively approved as soon as I can. I have tried to summarize this patch
> set as clearly and succinctly below as possible. Thanks!
You will need a sign-off from cygwin od mingw-w64 maintainer (CC'd).
While I can review the patch in the sense that it won't break generic
code, I don't know nothing about mingw-64 to give you any meaningful
advice.
Uros.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-02-10 10:32 ` [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Uros Bizjak
@ 2017-02-10 11:34 ` JonY
2017-02-10 17:20 ` Daniel Santos
2017-03-10 4:42 ` Daniel Santos
2017-02-10 17:55 ` Daniel Santos
1 sibling, 2 replies; 23+ messages in thread
From: JonY @ 2017-02-10 11:34 UTC (permalink / raw)
To: Uros Bizjak, Daniel Santos; +Cc: gcc-patches, Jan Hubicka, Sandra Loosemore
[-- Attachment #1.1: Type: text/plain, Size: 1371 bytes --]
On 02/10/2017 10:32 AM, Uros Bizjak wrote:
> On Tue, Feb 7, 2017 at 7:38 PM, Daniel Santos <daniel.santos@pobox.com> wrote:
>
>> Uros or Jan,
>> Please take this as a ping, as I never bothered pinging after submitting v2
>> since I found a few more issues with it. :) Although I realize this would be
>> a GCC 8 stage 1 item, I would like to try to get it finished up and
>> tentatively approved as soon as I can. I have tried to summarize this patch
>> set as clearly and succinctly below as possible. Thanks!
>
> You will need a sign-off from cygwin od mingw-w64 maintainer (CC'd).
> While I can review the patch in the sense that it won't break generic
> code, I don't know nothing about mingw-64 to give you any meaningful
> advice.
>
> Uros.
>
Hi,
Thanks for the code size reduction patch, I have a few questions:
1. How does code compiled with -moutline-msabi-xlogues interact with
older code compiled without it? Are these only called on ABI transition?
2. Does this mean code compiled with -moutline-msabi-xlogues is not
usable with older GCC? (no a problem, just something to note).
3. Is the old behavior (emit inline code) still default?
mingw-w64 itself does not use any ms_abi/sysv_abi marked functions
internally, so it should be unaffected. I don't think Cygwin uses any
either, but I need to double check.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 829 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues
2017-02-10 4:43 ` Daniel Santos
@ 2017-02-10 16:54 ` Sandra Loosemore
2017-02-10 17:32 ` Daniel Santos
2017-04-01 22:37 ` Daniel Santos
0 siblings, 2 replies; 23+ messages in thread
From: Sandra Loosemore @ 2017-02-10 16:54 UTC (permalink / raw)
To: Daniel Santos, Bernhard Reutner-Fischer, gcc-patches
On 02/09/2017 09:46 PM, Daniel Santos wrote:
> On 02/08/2017 05:28 PM, Bernhard Reutner-Fischer wrote:
>> On 7 February 2017 19:40:17 CET, Daniel Santos
>> <daniel.santos@pobox.com> wrote:
>>
>>> + { "-mmoutline-msabi-xlogues", MASK_OUTLINE_MSABI_XLOGUES }
>>> };
>> s/mm/m/
I'd like to re-iterate my previous request that the option be renamed
-mno-inline-msabi-xlogues. No other option that controls inlining uses
"outline" for the negative (disabling inlining). We have way too many
options and the least we can do is try to make them use consistent
conventions.
-Sandra
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-02-10 11:34 ` JonY
@ 2017-02-10 17:20 ` Daniel Santos
2017-02-11 0:30 ` JonY
2017-03-10 4:42 ` Daniel Santos
1 sibling, 1 reply; 23+ messages in thread
From: Daniel Santos @ 2017-02-10 17:20 UTC (permalink / raw)
To: JonY, Uros Bizjak; +Cc: gcc-patches, Jan Hubicka, Sandra Loosemore
On 02/10/2017 05:34 AM, JonY wrote:
> Hi,
>
> Thanks for the code size reduction patch, I have a few questions:
Thanks for your review!
> 1. How does code compiled with -moutline-msabi-xlogues interact with
> older code compiled without it? Are these only called on ABI transition?
These are only called in functions with the ABI transition from ms_abi
to sysv_abi. I'm not completely sure I understand the other question,
however. I haven't specifically tested linking two object files, one
built with and without the option enabled, but I wouldn't expect it to
produce any problems. Nor have I tested linking object files built with
-moutline-msabi-xlogues with object files built with an older compiler.
> 2. Does this mean code compiled with -moutline-msabi-xlogues is not
> usable with older GCC? (no a problem, just something to note).
As above, I haven't tested this scenario, but I don't anticipate a
problem other than general gcc version issues (like the default C++ ABI
version, etc.). I can set up tests for this, but it will take me a
little time. I used to have 12 gcc versions installed but I've rebuilt
my system since then and I only have 4 now. The nice thing about Gentoo
is that you build every package yourself. The bad thing about Gentoo is
that you build every package yourself.
> 3. Is the old behavior (emit inline code) still default?
Yes. And I believe that it was for this reason that Sandra (in CC)
recommended renaming the feature to -m[no-]inline-msabi-xlogues with the
default to "inline" since "inline" vs "no-inline" is the more common
language used. Also, the older behavior is still what is emitted for
ABI transition functions under various conditions (below), some just
because I haven't examined them yet.
+ 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");
In fact, DRAP used to be one of these cases and I only got that working with this last version of the patch set.
> mingw-w64 itself does not use any ms_abi/sysv_abi marked functions
> internally, so it should be unaffected. I don't think Cygwin uses any
> either, but I need to double check.
Of course, ms_abi is gcc's default on Windows so it would be sysv_abi
functions. I'm *guessing* that just about everything with Cygwin is
built for Windows, but it would also make sense if (in some odd case) a
binary built with sysv_abi is used by something and that library or
program makes the ABI transition when using said hypothetical library.
Even in these cases, I would not anticipate a problem, although any use
of SEH would inhibit the optimization. Of course, I haven't *tested*
this, so I'm only speaking from what I know. :)
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues
2017-02-10 16:54 ` Sandra Loosemore
@ 2017-02-10 17:32 ` Daniel Santos
2017-04-01 22:37 ` Daniel Santos
1 sibling, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-10 17:32 UTC (permalink / raw)
To: Sandra Loosemore, Bernhard Reutner-Fischer, gcc-patches,
Uros Bizjak, Jan Hubicka, JonY
On 02/10/2017 10:54 AM, Sandra Loosemore wrote:
> On 02/09/2017 09:46 PM, Daniel Santos wrote:
>> On 02/08/2017 05:28 PM, Bernhard Reutner-Fischer wrote:
>>> On 7 February 2017 19:40:17 CET, Daniel Santos
>>> <daniel.santos@pobox.com> wrote:
>>>
>>>> + { "-mmoutline-msabi-xlogues", MASK_OUTLINE_MSABI_XLOGUES }
>>>> };
>>> s/mm/m/
>
> I'd like to re-iterate my previous request that the option be renamed
> -mno-inline-msabi-xlogues. No other option that controls inlining
> uses "outline" for the negative (disabling inlining). We have way too
> many options and the least we can do is try to make them use
> consistent conventions.
>
> -Sandra
Thank you. I was just mentioning that and I agree, I just thought I
should get feedback from i386 guys. I did quote you in the main email on
this issue:
> For now, I have called this feature -moutline-msabi-xlogues, but
> Sandra Loosemore has this suggestion:
> (https://gcc.gnu.org/ml/gcc-patches/2016-11/msg02670.html)
>
>> Just as a suggestion (I'm not an i386 maintainer), I'd recommend
>> spelling the name of this option -mno-inline-msabi-xlogues instead of
>> -moutline-msabi-xlogues, and making the default -minline-msabi-xlogues.
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-02-10 10:32 ` [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Uros Bizjak
2017-02-10 11:34 ` JonY
@ 2017-02-10 17:55 ` Daniel Santos
1 sibling, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-10 17:55 UTC (permalink / raw)
To: Uros Bizjak; +Cc: gcc-patches, Jan Hubicka, Sandra Loosemore, 10walls
On 02/10/2017 04:32 AM, Uros Bizjak wrote:
> On Tue, Feb 7, 2017 at 7:38 PM, Daniel Santos <daniel.santos@pobox.com> wrote:
>
> You will need a sign-off from cygwin od mingw-w64 maintainer (CC'd).
> While I can review the patch in the sense that it won't break generic
> code, I don't know nothing about mingw-64 to give you any meaningful
> advice.
>
> Uros.
Thanks for your review! I know that this is a large patch set and I
know that I could have chosen a simpler "first gcc project", but this
particular issue is one that's been itching me for a little while. Also
please let me know your opinion about renaming this to
-mno-inline-msabi-xlogues (with the default being -minline-msabi-xlogues).
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-02-10 17:20 ` Daniel Santos
@ 2017-02-11 0:30 ` JonY
2017-02-11 7:24 ` Daniel Santos
2017-03-13 18:40 ` Daniel Santos
0 siblings, 2 replies; 23+ messages in thread
From: JonY @ 2017-02-11 0:30 UTC (permalink / raw)
To: Daniel Santos, Uros Bizjak; +Cc: gcc-patches, Jan Hubicka, Sandra Loosemore
[-- Attachment #1.1: Type: text/plain, Size: 1289 bytes --]
On 02/10/2017 05:23 PM, Daniel Santos wrote:
> On 02/10/2017 05:34 AM, JonY wrote:
>> Hi,
>> mingw-w64 itself does not use any ms_abi/sysv_abi marked functions
>> internally, so it should be unaffected. I don't think Cygwin uses any
>> either, but I need to double check.
>
> Of course, ms_abi is gcc's default on Windows so it would be sysv_abi
> functions. I'm *guessing* that just about everything with Cygwin is
> built for Windows, but it would also make sense if (in some odd case) a
> binary built with sysv_abi is used by something and that library or
> program makes the ABI transition when using said hypothetical library.
> Even in these cases, I would not anticipate a problem, although any use
> of SEH would inhibit the optimization. Of course, I haven't *tested*
> this, so I'm only speaking from what I know. :)
>
Cygwin has internal functions marked ms_abi but none with sysv_abi, so
it will be unaffected by this change. Most 64bit mingw-w64 toolchains
are built with SEH for exception handling though, but since it is
disabled, it shouldn't break anything.
If its not too much to ask, please do a gcc build targeting 32bit/64bit
mingw-w64 and Cygwin, it'll make solid evidence that the changes do not
break the compiler.
Thanks.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 829 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-02-11 0:30 ` JonY
@ 2017-02-11 7:24 ` Daniel Santos
2017-03-13 18:40 ` Daniel Santos
1 sibling, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-02-11 7:24 UTC (permalink / raw)
To: JonY, Uros Bizjak; +Cc: gcc-patches, Jan Hubicka, Sandra Loosemore
On 02/10/2017 06:20 PM, JonY wrote:
> On 02/10/2017 05:23 PM, Daniel Santos wrote:
>> On 02/10/2017 05:34 AM, JonY wrote:
>>> Hi,
>>> mingw-w64 itself does not use any ms_abi/sysv_abi marked functions
>>> internally, so it should be unaffected. I don't think Cygwin uses any
>>> either, but I need to double check.
>> Of course, ms_abi is gcc's default on Windows so it would be sysv_abi
>> functions. I'm *guessing* that just about everything with Cygwin is
>> built for Windows, but it would also make sense if (in some odd case) a
>> binary built with sysv_abi is used by something and that library or
>> program makes the ABI transition when using said hypothetical library.
>> Even in these cases, I would not anticipate a problem, although any use
>> of SEH would inhibit the optimization. Of course, I haven't *tested*
>> this, so I'm only speaking from what I know. :)
>>
> Cygwin has internal functions marked ms_abi but none with sysv_abi, so
> it will be unaffected by this change. Most 64bit mingw-w64 toolchains
> are built with SEH for exception handling though, but since it is
> disabled, it shouldn't break anything.
>
> If its not too much to ask, please do a gcc build targeting 32bit/64bit
> mingw-w64 and Cygwin, it'll make solid evidence that the changes do not
> break the compiler.
>
> Thanks.
Will do. I'll even run a query afterwards and see if anything in Cygwin
actually makes cross-ABI functions just for the sake of our collective
curiosity. It's always nice to know. It is important that I make sure
we don't break anything in Cygwin, being that I've mostly been thinking
about Wine.
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-02-10 11:34 ` JonY
2017-02-10 17:20 ` Daniel Santos
@ 2017-03-10 4:42 ` Daniel Santos
2017-03-30 17:55 ` Daniel Santos
1 sibling, 1 reply; 23+ messages in thread
From: Daniel Santos @ 2017-03-10 4:42 UTC (permalink / raw)
To: JonY, Uros Bizjak; +Cc: gcc-patches
It's been a while and I wanted to post a status update. My new tests
needed a few fix-ups to work on Cygwin, but they pass.
As for the rest, it turns out that running the testsuite on Cygwin is a
vertable nightmare. The tests are NOT even correct because they load
the shared libs (dlls) that are installed on the *system* and NOT the
ones in the build tree! (libgcc, libgfortran, libatomic, etc.) I have
opened a report for this
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79867) and I have a
patchset that appears to resolve the the problem, although it needs much
cleaning up and half of it is on the DejaGnu side. This problem appears
to have been around for a long time.
Although my VM is on an quad core w/ hyperthreading processor (so 8
cores), if I run more than one make job I get broken pipes. This
appears to be one of those problems that nobody has a solution to, only
tweaks that they *believe* prevents the problem from occurring *as
often*! If I run a single make job with -j1, I am very likely to not
get the problem, but never assured. There are also many jobs that are
timing out, but I'm hoping to get a descent set of tests on this latest run.
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-02-11 0:30 ` JonY
2017-02-11 7:24 ` Daniel Santos
@ 2017-03-13 18:40 ` Daniel Santos
1 sibling, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-03-13 18:40 UTC (permalink / raw)
To: Uros Bizjak; +Cc: gcc-patches, JonY
Uros,
Testing on Cygwin only turns out to be a nightmare, but I've finally
gotten some test results that I'm calling "clean enough". I have only
done 64-bit Cygwin thus far, (still need 32-bit Cygwin as well as 32/64
MinGW), but I've hit a snag. The first patch set ("Use aligned SSE movs
for re-aligned MS ABI pro/epilogues" --
https://gcc.gnu.org/ml/gcc-patches/2016-12/msg01859.html) modifies how
we select a base register and offset for accessing the stack. The test
gcc.target/x86_64/abi/callabi/vaarg-5a.c uses a realigned stack pointer
in a cross-abi case that triggers an internal compiler error at
config/i386/winnt.c:1132 where i386_pe_seh_unwind_emit() doesn't like
REG_CFA_EXPRESSION in the notes. This is the snippet:
for (note = REG_NOTES (insn); note ; note = XEXP (note, 1))
{
switch (REG_NOTE_KIND (note))
{
case REG_FRAME_RELATED_EXPR:
pat = XEXP (note, 0);
goto found;
case REG_CFA_DEF_CFA:
case REG_CFA_EXPRESSION:
/* Only emitted with DRAP, which we disable. */
gcc_unreachable ();
break;
This is the chunk that introduces this new behavior:
@@ -12824,6 +12878,13 @@ ix86_emit_save_reg_using_mov (machine_mode mode, unsigned int regno,
}
}
+ else if (base == stack_pointer_rtx && m->fs.sp_realigned
+ && cfa_offset >= m->fs.sp_realigned_offset)
+ {
+ gcc_checking_assert (stack_realign_fp);
+ add_reg_note (insn, REG_CFA_EXPRESSION, gen_rtx_SET (mem, reg));
+ }
+
/* The memory may not be relative to the current CFA register,
which means that we may need to generate a new pattern for
use by the unwind info. */
And this is a sample of pre- and post-patch in pro_and_epilogue:
RTL pre-patch:
(insn/f 41 40 42 2 (set (mem/c:V4SF (plus:DI (reg/f:DI 6 bp)
(const_int -160 [0xffffffffffffff60])) [6 S16 A64])
(reg:V4SF 27 xmm6)) "/c/Users/daniel/proj/sys/gcc/github/gcc/testsuite/gcc.target/x86_64/abi/callabi/vaarg-5b.c":29 -1
(nil))
RTL post-patch:
(insn/f 41 40 42 2 (set (mem/c:V4SF (plus:DI (reg/f:DI 7 sp)
(const_int 48 [0x30])) [6 S16 A128])
(reg:V4SF 27 xmm6)) "/c/Users/daniel/proj/sys/gcc/github/gcc/testsuite/gcc.target/x86_64/abi/callabi/vaarg-5b.c":29 -1
(expr_list:REG_CFA_EXPRESSION (set (mem/c:V4SF (plus:DI (reg/f:DI 7 sp)
(const_int 48 [0x30])) [6 S16 A128])
(reg:V4SF 27 xmm6))
(nil)))
I haven't learned much of the dwarf code so I can't fully appreciate the
function of all of these notes, but if we're using the SP should I just
omit the note and let dwarf intuit the insn? The test in
i386_pe_seh_unwind_emit() presumes that if we're using
REG_CFA_EXPRESSION then we've used DRAP, but that isn't the case after
this patch. Can you please advise on the correct solution? My current
guess is to just remove the above chunk (or at least remove the note).
Also of note, I need to do more analysis on why my tests did not expose
this flaw, since va args is something that it tests.
Thanks!
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-03-10 4:42 ` Daniel Santos
@ 2017-03-30 17:55 ` Daniel Santos
2017-03-30 23:28 ` JonY
0 siblings, 1 reply; 23+ messages in thread
From: Daniel Santos @ 2017-03-30 17:55 UTC (permalink / raw)
To: JonY; +Cc: Uros Bizjak, gcc-patches
I have finally completed all tests for Cygwin and MinGW both 32- &
64-bit with no additional test failures. There are still 567 tests
failing both pre- and post-patch with error "error while loading shared
libraries: cyggfortran-4.dll: cannot open shared object file: No such
file or directory" in all 32-bit tests even after my (fairly crude)
patch to address that problem. So as a separate issue, I don't yet have
a clean patch set to resolve the windows dll search path issue
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79867).
I had to change the test program, as I was dependent upon XSI extensions
which aren't available on Cygwin, so I'll need to repost that. Also, I
had to make one small change in the "aligned SSE MOVs" patch, disabling
it on SEH targets since gcc/config/i386/winnt.c does not currently
support the REG_CFA_EXPRESSION note in its unwind emit. This
optimization primarily targets 64-bit Wine anyway, where stack
realignment is now required.
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues
2017-03-30 17:55 ` Daniel Santos
@ 2017-03-30 23:28 ` JonY
0 siblings, 0 replies; 23+ messages in thread
From: JonY @ 2017-03-30 23:28 UTC (permalink / raw)
To: Daniel Santos; +Cc: Uros Bizjak, gcc-patches
[-- Attachment #1.1: Type: text/plain, Size: 1134 bytes --]
On 03/30/2017 05:50 PM, Daniel Santos wrote:
> I have finally completed all tests for Cygwin and MinGW both 32- &
> 64-bit with no additional test failures. There are still 567 tests
> failing both pre- and post-patch with error "error while loading shared
> libraries: cyggfortran-4.dll: cannot open shared object file: No such
> file or directory" in all 32-bit tests even after my (fairly crude)
> patch to address that problem. So as a separate issue, I don't yet have
> a clean patch set to resolve the windows dll search path issue
> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79867).
>
> I had to change the test program, as I was dependent upon XSI extensions
> which aren't available on Cygwin, so I'll need to repost that. Also, I
> had to make one small change in the "aligned SSE MOVs" patch, disabling
> it on SEH targets since gcc/config/i386/winnt.c does not currently
> support the REG_CFA_EXPRESSION note in its unwind emit. This
> optimization primarily targets 64-bit Wine anyway, where stack
> realignment is now required.
>
> Daniel
>
Very nice, thanks for running the tests.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 858 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues
2017-02-10 16:54 ` Sandra Loosemore
2017-02-10 17:32 ` Daniel Santos
@ 2017-04-01 22:37 ` Daniel Santos
1 sibling, 0 replies; 23+ messages in thread
From: Daniel Santos @ 2017-04-01 22:37 UTC (permalink / raw)
To: Uros Bizjak; +Cc: Sandra Loosemore, Bernhard Reutner-Fischer, gcc-patches
Uros, can I please get your opinion on this? I have no objections to
this, but I want to check with you first.
On 02/10/2017 10:54 AM, Sandra Loosemore wrote:
> I'd like to re-iterate my previous request that the option be renamed
> -mno-inline-msabi-xlogues. No other option that controls inlining
> uses "outline" for the negative (disabling inlining). We have way too
> many options and the least we can do is try to make them use
> consistent conventions.
>
> -Sandra
So the default would be -minline-msabi-xlogues and
-mno-inline-msabi-xlogues would enable this optimization.
Thanks,
Daniel
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2017-04-01 22:37 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-07 18:34 [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Daniel Santos
2017-02-07 18:36 ` [PATCH 4/8] [i386] Modify ix86_save_reg to optionally omit stub-managed registers Daniel Santos
2017-02-07 18:36 ` [PATCH 2/8] [i386] Add option -moutline-msabi-xlogues Daniel Santos
2017-02-08 23:28 ` Bernhard Reutner-Fischer
2017-02-10 4:43 ` Daniel Santos
2017-02-10 16:54 ` Sandra Loosemore
2017-02-10 17:32 ` Daniel Santos
2017-04-01 22:37 ` Daniel Santos
2017-02-07 18:36 ` [PATCH 3/8] [i386] Adds class xlouge_layout and new fields to struct machine_function Daniel Santos
2017-02-07 18:37 ` [PATCH 7/8] [i386] Add msabi pro/epilogue stubs to libgcc Daniel Santos
2017-02-07 18:37 ` [PATCH 1/8] [i386] Minor refactoring Daniel Santos
2017-02-07 18:37 ` [PATCH 6/8] [i386] Add patterns and predicates foutline-msabi-xlouges Daniel Santos
2017-02-07 18:37 ` [PATCH 5/8] [i386] Modify ix86_compute_frame_layout for foutline-msabi-xlogues Daniel Santos
2017-02-10 10:32 ` [RFC] [PATCH v3 0/8] [i386] Use out-of-line stubs for ms_abi pro/epilogues Uros Bizjak
2017-02-10 11:34 ` JonY
2017-02-10 17:20 ` Daniel Santos
2017-02-11 0:30 ` JonY
2017-02-11 7:24 ` Daniel Santos
2017-03-13 18:40 ` Daniel Santos
2017-03-10 4:42 ` Daniel Santos
2017-03-30 17:55 ` Daniel Santos
2017-03-30 23:28 ` JonY
2017-02-10 17:55 ` Daniel Santos
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).