* [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw
@ 2012-11-25 15:26 Kai Tietz
2012-11-28 15:57 ` Richard Henderson
0 siblings, 1 reply; 6+ messages in thread
From: Kai Tietz @ 2012-11-25 15:26 UTC (permalink / raw)
To: GCC Patches; +Cc: Richard Henderson
Hi,
the following patch adjusts used registers for thiscall-calling
convention thunks, so that there aren't register-collisions. Issue
was that thiscall-convention has different register-usage as
regparam, but it wasn't handled.
ChangeLog
2012-11-25 Kai Tietz
PR target/55171
* i386.c (get_scratch_register_on_entry): Handle
thiscall-convention.
(split_stack_prologue_scratch_regno): Likewise.
(ix86_static_chain): Likewise.
(x86_output_mi_thunk): Likewise.
Test on i686-w64-mingw32. Ok for apply?
Regards,
Kai
--- i386.c 2012-11-24 21:34:57.686148400 +0100
+++ i386.c2 2012-11-24 21:34:42.370272400 +0100
@@ -9655,6 +9655,8 @@ get_scratch_register_on_entry (struct sc
tree decl = current_function_decl, fntype = TREE_TYPE (decl);
bool fastcall_p
= lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
+ bool thiscall_p
+ = lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
bool static_chain_p = DECL_STATIC_CHAIN (decl);
int regparm = ix86_function_regparm (fntype, decl);
int drap_regno
@@ -9665,10 +9667,17 @@ get_scratch_register_on_entry (struct sc
if ((regparm < 1 || (fastcall_p && !static_chain_p))
&& drap_regno != AX_REG)
regno = AX_REG;
- else if (regparm < 2 && drap_regno != DX_REG)
+ /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx
+ for the static chain register. */
+ else if (thiscall_p && !static_chain_p)
+ regno = drap_regno != DX_REG ? DX_REG : AX_REG;
+ else if (thiscall_p && static_chain_p && drap_regno != AX_REG)
+ regno = AX_REG;
+ else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG)
regno = DX_REG;
/* ecx is the static chain register. */
- else if (regparm < 3 && !fastcall_p && !static_chain_p
+ else if (regparm < 3 && !fastcall_p && !thiscall_p
+ && !static_chain_p
&& drap_regno != CX_REG)
regno = CX_REG;
else if (ix86_save_reg (BX_REG, true))
@@ -11180,12 +11189,15 @@ split_stack_prologue_scratch_regno (void
return R11_REG;
else
{
- bool is_fastcall;
+ bool is_fastcall, is_thiscall;
int regparm;
is_fastcall = (lookup_attribute ("fastcall",
TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
!= NULL);
+ is_thiscall = (lookup_attribute ("thiscall",
+ TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
+ != NULL);
regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl);
if (is_fastcall)
@@ -11198,6 +11210,12 @@ split_stack_prologue_scratch_regno (void
}
return AX_REG;
}
+ else if (is_thiscall)
+ {
+ if (!DECL_STATIC_CHAIN (cfun->decl))
+ return DX_REG;
+ return AX_REG;
+ }
else if (regparm < 3)
{
if (!DECL_STATIC_CHAIN (cfun->decl))
@@ -25134,7 +25152,7 @@ ix86_static_chain (const_tree fndecl, bo
fntype = TREE_TYPE (fndecl);
ccvt = ix86_get_callcvt (fntype);
- if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0)
+ if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
{
/* Fastcall functions use ecx/edx for arguments, which leaves
us with EAX for the static chain.
@@ -25142,6 +25160,12 @@ ix86_static_chain (const_tree fndecl, bo
leaves us with EAX for the static chain. */
regno = AX_REG;
}
+ else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
+ {
+ /* Thiscall functions use ecx for arguments, which leaves
+ us with EDX for the static chain. */
+ regno = DX_REG;
+ }
else if (ix86_function_regparm (fntype, fndecl) == 3)
{
/* For regparm 3, we have no free call-clobbered registers in
@@ -34799,8 +34823,10 @@ x86_output_mi_thunk (FILE *file,
else
{
unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function));
- if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0)
+ if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
tmp_regno = AX_REG;
+ else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
+ tmp_regno = DX_REG;
else
tmp_regno = CX_REG;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw
2012-11-25 15:26 [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw Kai Tietz
@ 2012-11-28 15:57 ` Richard Henderson
2012-11-28 17:53 ` Kai Tietz
0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2012-11-28 15:57 UTC (permalink / raw)
To: Kai Tietz; +Cc: GCC Patches
On 11/25/2012 07:26 AM, Kai Tietz wrote:
> - if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0)
> + if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
> {
> /* Fastcall functions use ecx/edx for arguments, which leaves
> us with EAX for the static chain.
> @@ -25142,6 +25160,12 @@ ix86_static_chain (const_tree fndecl, bo
> leaves us with EAX for the static chain. */
> regno = AX_REG;
> }
> + else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
> + {
> + /* Thiscall functions use ecx for arguments, which leaves
> + us with EDX for the static chain. */
> + regno = DX_REG;
> + }
How is this not abi breakage? Why not leave eax as the static chain?
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw
2012-11-28 15:57 ` Richard Henderson
@ 2012-11-28 17:53 ` Kai Tietz
2012-11-28 18:33 ` Richard Henderson
0 siblings, 1 reply; 6+ messages in thread
From: Kai Tietz @ 2012-11-28 17:53 UTC (permalink / raw)
To: Richard Henderson; +Cc: GCC Patches
2012/11/28 Richard Henderson <rth@redhat.com>:
> On 11/25/2012 07:26 AM, Kai Tietz wrote:
>> - if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0)
>> + if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
>> {
>> /* Fastcall functions use ecx/edx for arguments, which leaves
>> us with EAX for the static chain.
>> @@ -25142,6 +25160,12 @@ ix86_static_chain (const_tree fndecl, bo
>> leaves us with EAX for the static chain. */
>> regno = AX_REG;
>> }
>> + else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
>> + {
>> + /* Thiscall functions use ecx for arguments, which leaves
>> + us with EDX for the static chain. */
>> + regno = DX_REG;
>> + }
>
> How is this not abi breakage? Why not leave eax as the static chain?
>
>
> r~
Well, interesting function here is get_scratch_register_on_entry,
where for thiscall (it uses just ecx) we have by this %eax remaining
as scratch. Well, we could switch that here and make scratch %edx for
thiscall?
Kai
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw
2012-11-28 17:53 ` Kai Tietz
@ 2012-11-28 18:33 ` Richard Henderson
2012-11-28 18:53 ` Kai Tietz
0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2012-11-28 18:33 UTC (permalink / raw)
To: Kai Tietz; +Cc: GCC Patches
On 11/28/2012 09:53 AM, Kai Tietz wrote:
> 2012/11/28 Richard Henderson <rth@redhat.com>:
>> On 11/25/2012 07:26 AM, Kai Tietz wrote:
>>> - if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0)
>>> + if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
>>> {
>>> /* Fastcall functions use ecx/edx for arguments, which leaves
>>> us with EAX for the static chain.
>>> @@ -25142,6 +25160,12 @@ ix86_static_chain (const_tree fndecl, bo
>>> leaves us with EAX for the static chain. */
>>> regno = AX_REG;
>>> }
>>> + else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
>>> + {
>>> + /* Thiscall functions use ecx for arguments, which leaves
>>> + us with EDX for the static chain. */
>>> + regno = DX_REG;
>>> + }
>>
>> How is this not abi breakage? Why not leave eax as the static chain?
>>
>>
>> r~
>
> Well, interesting function here is get_scratch_register_on_entry,
> where for thiscall (it uses just ecx) we have by this %eax remaining
> as scratch. Well, we could switch that here and make scratch %edx for
> thiscall?
Certainly we can.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw
2012-11-28 18:33 ` Richard Henderson
@ 2012-11-28 18:53 ` Kai Tietz
2012-11-28 20:09 ` Richard Henderson
0 siblings, 1 reply; 6+ messages in thread
From: Kai Tietz @ 2012-11-28 18:53 UTC (permalink / raw)
To: Richard Henderson; +Cc: GCC Patches
Fine. Here is a adjusted version which keeps old abi behavior for
chain-registers.
2012-11-28 Kai Tietz
PR target/55171
* i386.c (get_scratch_register_on_entry): Handle
thiscall-convention.
(split_stack_prologue_scratch_regno): Likewise.
(ix86_static_chain): Likewise.
(x86_output_mi_thunk): Likewise.
Test on i686-w64-mingw32. Ok for apply?
Regards,
Kai
Index: i386.c
===================================================================
--- i386.c (Revision 193781)
+++ i386.c (Arbeitskopie)
@@ -9655,6 +9655,8 @@
tree decl = current_function_decl, fntype = TREE_TYPE (decl);
bool fastcall_p
= lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
+ bool thiscall_p
+ = lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
bool static_chain_p = DECL_STATIC_CHAIN (decl);
int regparm = ix86_function_regparm (fntype, decl);
int drap_regno
@@ -9665,10 +9667,15 @@
if ((regparm < 1 || (fastcall_p && !static_chain_p))
&& drap_regno != AX_REG)
regno = AX_REG;
- else if (regparm < 2 && drap_regno != DX_REG)
+ /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx
+ for the static chain register. */
+ else if (thiscall_p && !static_chain_p && drap_regno != AX_REG)
+ regno = AX_REG;
+ else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG)
regno = DX_REG;
/* ecx is the static chain register. */
- else if (regparm < 3 && !fastcall_p && !static_chain_p
+ else if (regparm < 3 && !fastcall_p && !thiscall_p
+ && !static_chain_p
&& drap_regno != CX_REG)
regno = CX_REG;
else if (ix86_save_reg (BX_REG, true))
@@ -11180,12 +11187,15 @@
return R11_REG;
else
{
- bool is_fastcall;
+ bool is_fastcall, is_thiscall;
int regparm;
is_fastcall = (lookup_attribute ("fastcall",
TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
!= NULL);
+ is_thiscall = (lookup_attribute ("thiscall",
+ TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
+ != NULL);
regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl);
if (is_fastcall)
@@ -11198,6 +11208,12 @@
}
return AX_REG;
}
+ else if (is_thiscall)
+ {
+ if (!DECL_STATIC_CHAIN (cfun->decl))
+ return DX_REG;
+ return AX_REG;
+ }
else if (regparm < 3)
{
if (!DECL_STATIC_CHAIN (cfun->decl))
@@ -25134,7 +25150,7 @@
fntype = TREE_TYPE (fndecl);
ccvt = ix86_get_callcvt (fntype);
- if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0)
+ if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
{
/* Fastcall functions use ecx/edx for arguments, which leaves
us with EAX for the static chain.
@@ -25142,6 +25158,13 @@
leaves us with EAX for the static chain. */
regno = AX_REG;
}
+ else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
+ {
+ /* Thiscall functions use ecx for arguments, which leaves
+ us with EAX and EDX for the static chain.
+ We are using for abi-compatibility EAX. */
+ regno = AX_REG;
+ }
else if (ix86_function_regparm (fntype, fndecl) == 3)
{
/* For regparm 3, we have no free call-clobbered registers in
@@ -34799,8 +34822,10 @@
else
{
unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function));
- if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0)
+ if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
tmp_regno = AX_REG;
+ else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
+ tmp_regno = DX_REG;
else
tmp_regno = CX_REG;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw
2012-11-28 18:53 ` Kai Tietz
@ 2012-11-28 20:09 ` Richard Henderson
0 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2012-11-28 20:09 UTC (permalink / raw)
To: Kai Tietz; +Cc: GCC Patches
On 11/28/2012 10:52 AM, Kai Tietz wrote:
> 2012-11-28 Kai Tietz
>
> PR target/55171
> * i386.c (get_scratch_register_on_entry): Handle
> thiscall-convention.
> (split_stack_prologue_scratch_regno): Likewise.
> (ix86_static_chain): Likewise.
> (x86_output_mi_thunk): Likewise.
>
> Test on i686-w64-mingw32. Ok for apply?
Ok.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-11-28 20:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-25 15:26 [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw Kai Tietz
2012-11-28 15:57 ` Richard Henderson
2012-11-28 17:53 ` Kai Tietz
2012-11-28 18:33 ` Richard Henderson
2012-11-28 18:53 ` Kai Tietz
2012-11-28 20:09 ` Richard Henderson
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).