Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2017-03-29 Thread Andreas Schwab
On Mär 29 2017, Eric Botcazou  wrote:

>> But I still see some ICEs while running the testsuite,
>> which I haven't investigated yet.  And the original comment before this
>> hunk doesn't make sense at this point.
>
> The hunk in the 'else' arm of the big surrounding conditional?

Yes.  It talks about SYMBOL_REF which it clearly isn't at this point.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2017-03-29 Thread Eric Botcazou
> Thanks, this gets me further, the ada library now compiles with
> -mabi=ilp32.

Great, I think that you can apply it as obvious then, it's code which is only 
exercised in Ada and on ILP32 64-bit platforms so the risk is very low...

> But I still see some ICEs while running the testsuite,
> which I haven't investigated yet.  And the original comment before this
> hunk doesn't make sense at this point.

The hunk in the 'else' arm of the big surrounding conditional?

-- 
Eric Botcazou


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2017-03-29 Thread Andreas Schwab
On Mär 28 2017, Eric Botcazou  wrote:

>> That needs to use ptr_mode, not Pmode.
>
> I don't think so, the whole computation is in Pmode.  Could you try something 
> similar to what is done in the 'else' arm of the big surrounding conditional?

Thanks, this gets me further, the ada library now compiles with
-mabi=ilp32.  But I still see some ICEs while running the testsuite,
which I haven't investigated yet.  And the original comment before this
hunk doesn't make sense at this point.

Andreas.

diff --git a/gcc/calls.c b/gcc/calls.c
index 61caf4ca75..c92e35ea5a 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -206,6 +206,9 @@ prepare_call_address (tree fndecl_or_type, rtx funexp, rtx 
static_chain_value,
  DECL_STATIC_CHAIN (fndecl_or_type) = 1;
  rtx chain = targetm.calls.static_chain (fndecl_or_type, false);
 
+ if (GET_MODE (funexp) != Pmode)
+   funexp = convert_memory_address (Pmode, funexp);
+
  /* Avoid long live ranges around function calls.  */
  funexp = copy_to_mode_reg (Pmode, funexp);
 
-- 
2.12.2


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2017-03-28 Thread Eric Botcazou
> That needs to use ptr_mode, not Pmode.

I don't think so, the whole computation is in Pmode.  Could you try something 
similar to what is done in the 'else' arm of the big surrounding conditional?

-- 
Eric Botcazou


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2017-03-23 Thread Andreas Schwab
On Sep 04 2016, Eric Botcazou  wrote:

> Index: calls.c
> ===
> --- calls.c   (revision 239944)
> +++ calls.c   (working copy)
> @@ -183,17 +183,76 @@ static void restore_fixed_argument_area (rtx, rtx,
>  
>  rtx
>  prepare_call_address (tree fndecl_or_type, rtx funexp, rtx 
> static_chain_value,
> -   rtx *call_fusage, int reg_parm_seen, int sibcallp)
> +   rtx *call_fusage, int reg_parm_seen, int flags)
>  {
>/* Make a valid memory address and copy constants through pseudo-regs,
>   but not for a constant address if -fno-function-cse.  */
>if (GET_CODE (funexp) != SYMBOL_REF)
> -/* If we are using registers for parameters, force the
> -   function address into a register now.  */
> -funexp = ((reg_parm_seen
> -&& targetm.small_register_classes_for_mode_p (FUNCTION_MODE))
> -   ? force_not_mem (memory_address (FUNCTION_MODE, funexp))
> -   : memory_address (FUNCTION_MODE, funexp));
> +{
> +  /* If it's an indirect call by descriptor, generate code to perform
> +  runtime identification of the pointer and load the descriptor.  */
> +  if ((flags & ECF_BY_DESCRIPTOR) && !flag_trampolines)
> + {
> +   const int bit_val = targetm.calls.custom_function_descriptors;
> +   rtx call_lab = gen_label_rtx ();
> +
> +   gcc_assert (fndecl_or_type && TYPE_P (fndecl_or_type));
> +   fndecl_or_type
> + = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, NULL_TREE,
> +   fndecl_or_type);
> +   DECL_STATIC_CHAIN (fndecl_or_type) = 1;
> +   rtx chain = targetm.calls.static_chain (fndecl_or_type, false);
> +
> +   /* Avoid long live ranges around function calls.  */
> +   funexp = copy_to_mode_reg (Pmode, funexp);

That needs to use ptr_mode, not Pmode.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-07 Thread Eric Botcazou
> Yes I rebuilt everything and now it all looks good.  The previously
> failing testcases are now passing and no new regressions.  I must have had
> something set incorrectly in my environment on my first try.

Thanks for confirming.

-- 
Eric Botcazou


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-07 Thread Lynn A. Boger
Yes I rebuilt everything and now it all looks good.  The previously 
failing testcases


are now passing and no new regressions.  I must have had something set 
incorrectly


in my environment on my first try.

Thanks!

On 12/06/2016 04:26 PM, Eric Botcazou wrote:

I tried this patch applied against latest and it fixed the testcases
that I had reported as failing, but the patch also causes

libgo reflect testcase to fail.  Still testing to verify and will report
the failure details.

Please double check, as I can reproduce neither on PowerPC64 nor on x86-64.

In any case, the patch just reverts a problematic change so can do no harm.





Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-06 Thread Eric Botcazou
> > Btw, Ian, if the heap trampoline support is no longer used by the Go
> > compiler, you might want to remove it from the middle-end.
> 
> Yes, I suppose so.  The Go frontend hasn't used them for a while.

Speaking of obsolete stuff, do you have any opinion on the below patch?
  https://gcc.gnu.org/ml/gcc-patches/2016-10/msg01586.html

-- 
Eric Botcazou


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-06 Thread Eric Botcazou
> I tried this patch applied against latest and it fixed the testcases
> that I had reported as failing, but the patch also causes
> 
> libgo reflect testcase to fail.  Still testing to verify and will report
> the failure details.

Please double check, as I can reproduce neither on PowerPC64 nor on x86-64.

In any case, the patch just reverts a problematic change so can do no harm.

-- 
Eric Botcazou


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-06 Thread Lynn A. Boger
I tried this patch applied against latest and it fixed the testcases 
that I had reported as failing, but the patch also causes


libgo reflect testcase to fail.  Still testing to verify and will report 
the failure details.



On 12/06/2016 02:18 PM, Ian Lance Taylor wrote:

On Tue, Dec 6, 2016 at 9:52 AM, Eric Botcazou  wrote:

There are a couple of changes to the RTL expander for calls; they are
supposed to be transparent but they might have tripped on a latent issue.

Tentative fix attached, I need to test it extensively in Ada though.

Thanks.  Lynn, can you see if this patch fixes the bugs you see?


Btw, Ian, if the heap trampoline support is no longer used by the Go compiler,
you might want to remove it from the middle-end.

Yes, I suppose so.  The Go frontend hasn't used them for a while.

Ian






Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-06 Thread Ian Lance Taylor
On Tue, Dec 6, 2016 at 9:52 AM, Eric Botcazou  wrote:
>> There are a couple of changes to the RTL expander for calls; they are
>> supposed to be transparent but they might have tripped on a latent issue.
>
> Tentative fix attached, I need to test it extensively in Ada though.

Thanks.  Lynn, can you see if this patch fixes the bugs you see?

> Btw, Ian, if the heap trampoline support is no longer used by the Go compiler,
> you might want to remove it from the middle-end.

Yes, I suppose so.  The Go frontend hasn't used them for a while.

Ian


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-06 Thread Eric Botcazou
> There are a couple of changes to the RTL expander for calls; they are
> supposed to be transparent but they might have tripped on a latent issue.

Tentative fix attached, I need to test it extensively in Ada though.

Btw, Ian, if the heap trampoline support is no longer used by the Go compiler, 
you might want to remove it from the middle-end.

-- 
Eric BotcazouIndex: calls.c
===
--- calls.c	(revision 243245)
+++ calls.c	(working copy)
@@ -3427,13 +3427,6 @@ expand_call (tree exp, rtx target, int i
   if (STRICT_ALIGNMENT)
 	store_unaligned_arguments_into_pseudos (args, num_actuals);
 
-  /* Prepare the address of the call.  This must be done before any
-	 register parameters is loaded for find_first_parameter_load to
-	 work properly in the presence of descriptors.  */
-  funexp = prepare_call_address (fndecl ? fndecl : fntype, funexp,
- static_chain_value, _fusage,
- reg_parm_seen, flags);
-
   /* Now store any partially-in-registers parm.
 	 This is the last place a block-move can happen.  */
   if (reg_parm_seen)
@@ -3544,6 +3537,9 @@ expand_call (tree exp, rtx target, int i
 	}
 
   after_args = get_last_insn ();
+  funexp = prepare_call_address (fndecl ? fndecl : fntype, funexp,
+ static_chain_value, _fusage,
+ reg_parm_seen, flags);
   load_register_parameters (args, num_actuals, _fusage, flags,
 pass == 0, _failure);
 


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-05 Thread Ian Lance Taylor
On Mon, Dec 5, 2016 at 1:29 PM, Lynn A. Boger
 wrote:
> I think you mean https://github.com/golang/go/issues/18200.

Yes, thanks, I meant to write https://golang.org/issue/18200.

Ian

> On 12/05/2016 02:52 PM, Ian Lance Taylor wrote:
>>
>> On Sun, Sep 4, 2016 at 1:10 PM, Eric Botcazou 
>> wrote:
>>>
>>> 2016-07-04  Eric Botcazou  
>>>
>>>  PR ada/37139
>>>  PR ada/67205
>>>  * common.opt (-ftrampolines): New option.
>>>  * doc/invoke.texi (Code Gen Options): Document it.
>>>  * doc/tm.texi.in (Trampolines):
>>> AddTARGET_CUSTOM_FUNCTION_DESCRIPTORS
>>>  * doc/tm.texi: Regenerate.
>>>  * builtins.def: Add init_descriptor and adjust_descriptor.
>>>  * builtins.c (expand_builtin_init_trampoline): Do not issue a
>>> warning
>>>  on platforms with descriptors.
>>>  (expand_builtin_init_descriptor): New function.
>>>  (expand_builtin_adjust_descriptor): Likewise.
>>>  (expand_builtin) : New case.
>>>  : Likewise.
>>>  * calls.c (prepare_call_address): Remove SIBCALLP parameter and
>>> add
>>>  FLAGS parameter.  Deal with indirect calls by descriptor and
>>> adjust.
>>>  Set STATIC_CHAIN_REG_P on the static chain register, if any.
>>>  (call_expr_flags): Set ECF_BY_DESCRIPTOR for calls by
>>> descriptor.
>>>  (expand_call): Likewise.  Move around call to
>>> prepare_call_address
>>>  and pass all flags to it.
>>>  * cfgexpand.c (expand_call_stmt): Reinstate
>>> CALL_EXPR_BY_DESCRIPTOR.
>>>  * gimple.h (enum gf_mask): New GF_CALL_BY_DESCRIPTOR value.
>>>  (gimple_call_set_by_descriptor): New setter.
>>>  (gimple_call_by_descriptor_p): New getter.
>>>  * gimple.c (gimple_build_call_from_tree):
>>> SetCALL_EXPR_BY_DESCRIPTOR.
>>>  (gimple_call_flags): Deal with GF_CALL_BY_DESCRIPTOR.
>>>  * langhooks.h (struct lang_hooks): Add
>>> custom_function_descriptors.
>>>  * langhooks-def.h (LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS):
>>> Define.
>>>  (LANG_HOOKS_INITIALIZER): Add
>>> LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS.
>>>  * rtl.h (STATIC_CHAIN_REG_P): New macro.
>>>  * rtlanal.c (find_first_parameter_load): Skip static chain
>>> registers.
>>>  * target.def (custom_function_descriptors): New POD hook.
>>>  * tree.h (FUNC_ADDR_BY_DESCRIPTOR): New flag on ADDR_EXPR.
>>>  (CALL_EXPR_BY_DESCRIPTOR): New flag on CALL_EXPR.
>>>  * tree-core.h (ECF_BY_DESCRIPTOR): New mask.
>>>  Document FUNC_ADDR_BY_DESCRIPTOR and CALL_EXPR_BY_DESCRIPTOR.
>>>  * tree.c (make_node_stat) : Use
>>> FUNCTION_ALIGNMENT.
>>>  (build_common_builtin_nodes): Initialize init_descriptor and
>>>  adjust_descriptor.
>>>  * tree-nested.c: Include target.h.
>>>  (struct nesting_info): Add 'any_descr_created' field.
>>>  (get_descriptor_type): New function.
>>>  (lookup_element_for_decl): New function extracted from...
>>>  (create_field_for_decl): Likewise.
>>>  (lookup_tramp_for_decl): ...here.  Adjust.
>>>  (lookup_descr_for_decl): New function.
>>>  (convert_tramp_reference_op): Deal with descriptors.
>>>  (build_init_call_stmt): New function extracted from...
>>>  (finalize_nesting_tree_1): ...here.  Adjust and deal
>>> withdescriptors.
>>>  * defaults.h (FUNCTION_ALIGNMENT): Define.
>>>  (TRAMPOLINE_ALIGNMENT): Set to above instead of
>>> FUNCTION_BOUNDARY.
>>
>> According to https://golang.org/cl/18200, this change broke Go on PPC64le.
>>
>> I haven't investigated myself and I don't know why.  Go does not use
>> stack trampolines for function closures.  It does use function
>> closures, but they are built on the heap.  It also uses closures
>> mediated by libffi.  The Go frontend does not enable custom function
>> descriptors.
>>
>> It should be possible to recreate the problem by configuring with
>> --enable-languages=go and running `make
>> RUNTESTFLAGS="go-test.exp=recover.go" check-gcc-go`.
>>
>> Ian
>>
>>
>


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-05 Thread Eric Botcazou
> According to https://golang.org/cl/18200, this change broke Go on PPC64le.

Any other platform where this also happened?

> I haven't investigated myself and I don't know why.  Go does not use
> stack trampolines for function closures.  It does use function
> closures, but they are built on the heap.  It also uses closures
> mediated by libffi.  The Go frontend does not enable custom function
> descriptors.

There are a couple of changes to the RTL expander for calls; they are supposed 
to be transparent but they might have tripped on a latent issue.

> It should be possible to recreate the problem by configuring with
> --enable-languages=go and running `make
> RUNTESTFLAGS="go-test.exp=recover.go" check-gcc-go`.

Thanks, I'll try to reproduce tomorrow.

-- 
Eric Botcazou


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-05 Thread Lynn A. Boger

I think you mean https://github.com/golang/go/issues/18200.

- Lynn

On 12/05/2016 02:52 PM, Ian Lance Taylor wrote:

On Sun, Sep 4, 2016 at 1:10 PM, Eric Botcazou  wrote:

2016-07-04  Eric Botcazou  

 PR ada/37139
 PR ada/67205
 * common.opt (-ftrampolines): New option.
 * doc/invoke.texi (Code Gen Options): Document it.
 * doc/tm.texi.in (Trampolines): AddTARGET_CUSTOM_FUNCTION_DESCRIPTORS
 * doc/tm.texi: Regenerate.
 * builtins.def: Add init_descriptor and adjust_descriptor.
 * builtins.c (expand_builtin_init_trampoline): Do not issue a warning
 on platforms with descriptors.
 (expand_builtin_init_descriptor): New function.
 (expand_builtin_adjust_descriptor): Likewise.
 (expand_builtin) : New case.
 : Likewise.
 * calls.c (prepare_call_address): Remove SIBCALLP parameter and add
 FLAGS parameter.  Deal with indirect calls by descriptor and adjust.
 Set STATIC_CHAIN_REG_P on the static chain register, if any.
 (call_expr_flags): Set ECF_BY_DESCRIPTOR for calls by descriptor.
 (expand_call): Likewise.  Move around call to prepare_call_address
 and pass all flags to it.
 * cfgexpand.c (expand_call_stmt): Reinstate CALL_EXPR_BY_DESCRIPTOR.
 * gimple.h (enum gf_mask): New GF_CALL_BY_DESCRIPTOR value.
 (gimple_call_set_by_descriptor): New setter.
 (gimple_call_by_descriptor_p): New getter.
 * gimple.c (gimple_build_call_from_tree): SetCALL_EXPR_BY_DESCRIPTOR.
 (gimple_call_flags): Deal with GF_CALL_BY_DESCRIPTOR.
 * langhooks.h (struct lang_hooks): Add custom_function_descriptors.
 * langhooks-def.h (LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS): Define.
 (LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS.
 * rtl.h (STATIC_CHAIN_REG_P): New macro.
 * rtlanal.c (find_first_parameter_load): Skip static chain registers.
 * target.def (custom_function_descriptors): New POD hook.
 * tree.h (FUNC_ADDR_BY_DESCRIPTOR): New flag on ADDR_EXPR.
 (CALL_EXPR_BY_DESCRIPTOR): New flag on CALL_EXPR.
 * tree-core.h (ECF_BY_DESCRIPTOR): New mask.
 Document FUNC_ADDR_BY_DESCRIPTOR and CALL_EXPR_BY_DESCRIPTOR.
 * tree.c (make_node_stat) : Use FUNCTION_ALIGNMENT.
 (build_common_builtin_nodes): Initialize init_descriptor and
 adjust_descriptor.
 * tree-nested.c: Include target.h.
 (struct nesting_info): Add 'any_descr_created' field.
 (get_descriptor_type): New function.
 (lookup_element_for_decl): New function extracted from...
 (create_field_for_decl): Likewise.
 (lookup_tramp_for_decl): ...here.  Adjust.
 (lookup_descr_for_decl): New function.
 (convert_tramp_reference_op): Deal with descriptors.
 (build_init_call_stmt): New function extracted from...
 (finalize_nesting_tree_1): ...here.  Adjust and deal withdescriptors.
 * defaults.h (FUNCTION_ALIGNMENT): Define.
 (TRAMPOLINE_ALIGNMENT): Set to above instead of FUNCTION_BOUNDARY.

According to https://golang.org/cl/18200, this change broke Go on PPC64le.

I haven't investigated myself and I don't know why.  Go does not use
stack trampolines for function closures.  It does use function
closures, but they are built on the heap.  It also uses closures
mediated by libffi.  The Go frontend does not enable custom function
descriptors.

It should be possible to recreate the problem by configuring with
--enable-languages=go and running `make
RUNTESTFLAGS="go-test.exp=recover.go" check-gcc-go`.

Ian






Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-12-05 Thread Ian Lance Taylor
On Sun, Sep 4, 2016 at 1:10 PM, Eric Botcazou  wrote:
>
> 2016-07-04  Eric Botcazou  
>
> PR ada/37139
> PR ada/67205
> * common.opt (-ftrampolines): New option.
> * doc/invoke.texi (Code Gen Options): Document it.
> * doc/tm.texi.in (Trampolines): AddTARGET_CUSTOM_FUNCTION_DESCRIPTORS
> * doc/tm.texi: Regenerate.
> * builtins.def: Add init_descriptor and adjust_descriptor.
> * builtins.c (expand_builtin_init_trampoline): Do not issue a warning
> on platforms with descriptors.
> (expand_builtin_init_descriptor): New function.
> (expand_builtin_adjust_descriptor): Likewise.
> (expand_builtin) : New case.
> : Likewise.
> * calls.c (prepare_call_address): Remove SIBCALLP parameter and add
> FLAGS parameter.  Deal with indirect calls by descriptor and adjust.
> Set STATIC_CHAIN_REG_P on the static chain register, if any.
> (call_expr_flags): Set ECF_BY_DESCRIPTOR for calls by descriptor.
> (expand_call): Likewise.  Move around call to prepare_call_address
> and pass all flags to it.
> * cfgexpand.c (expand_call_stmt): Reinstate CALL_EXPR_BY_DESCRIPTOR.
> * gimple.h (enum gf_mask): New GF_CALL_BY_DESCRIPTOR value.
> (gimple_call_set_by_descriptor): New setter.
> (gimple_call_by_descriptor_p): New getter.
> * gimple.c (gimple_build_call_from_tree): SetCALL_EXPR_BY_DESCRIPTOR.
> (gimple_call_flags): Deal with GF_CALL_BY_DESCRIPTOR.
> * langhooks.h (struct lang_hooks): Add custom_function_descriptors.
> * langhooks-def.h (LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS): Define.
> (LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS.
> * rtl.h (STATIC_CHAIN_REG_P): New macro.
> * rtlanal.c (find_first_parameter_load): Skip static chain registers.
> * target.def (custom_function_descriptors): New POD hook.
> * tree.h (FUNC_ADDR_BY_DESCRIPTOR): New flag on ADDR_EXPR.
> (CALL_EXPR_BY_DESCRIPTOR): New flag on CALL_EXPR.
> * tree-core.h (ECF_BY_DESCRIPTOR): New mask.
> Document FUNC_ADDR_BY_DESCRIPTOR and CALL_EXPR_BY_DESCRIPTOR.
> * tree.c (make_node_stat) : Use FUNCTION_ALIGNMENT.
> (build_common_builtin_nodes): Initialize init_descriptor and
> adjust_descriptor.
> * tree-nested.c: Include target.h.
> (struct nesting_info): Add 'any_descr_created' field.
> (get_descriptor_type): New function.
> (lookup_element_for_decl): New function extracted from...
> (create_field_for_decl): Likewise.
> (lookup_tramp_for_decl): ...here.  Adjust.
> (lookup_descr_for_decl): New function.
> (convert_tramp_reference_op): Deal with descriptors.
> (build_init_call_stmt): New function extracted from...
> (finalize_nesting_tree_1): ...here.  Adjust and deal withdescriptors.
> * defaults.h (FUNCTION_ALIGNMENT): Define.
> (TRAMPOLINE_ALIGNMENT): Set to above instead of FUNCTION_BOUNDARY.

According to https://golang.org/cl/18200, this change broke Go on PPC64le.

I haven't investigated myself and I don't know why.  Go does not use
stack trampolines for function closures.  It does use function
closures, but they are built on the heap.  It also uses closures
mediated by libffi.  The Go frontend does not enable custom function
descriptors.

It should be possible to recreate the problem by configuring with
--enable-languages=go and running `make
RUNTESTFLAGS="go-test.exp=recover.go" check-gcc-go`.

Ian


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-09-12 Thread Jeff Law

On 09/04/2016 02:10 PM, Eric Botcazou wrote:

This is the common infrastructure part.  As explained in the initial message,
nothing is activated unless both the language and the target opt in.


2016-07-04  Eric Botcazou  

PR ada/37139
PR ada/67205
* common.opt (-ftrampolines): New option.
* doc/invoke.texi (Code Gen Options): Document it.
* doc/tm.texi.in (Trampolines): AddTARGET_CUSTOM_FUNCTION_DESCRIPTORS
* doc/tm.texi: Regenerate.
* builtins.def: Add init_descriptor and adjust_descriptor.
* builtins.c (expand_builtin_init_trampoline): Do not issue a warning
on platforms with descriptors.
(expand_builtin_init_descriptor): New function.
(expand_builtin_adjust_descriptor): Likewise.
(expand_builtin) : New case.
: Likewise.
* calls.c (prepare_call_address): Remove SIBCALLP parameter and add
FLAGS parameter.  Deal with indirect calls by descriptor and adjust.
Set STATIC_CHAIN_REG_P on the static chain register, if any.
(call_expr_flags): Set ECF_BY_DESCRIPTOR for calls by descriptor.
(expand_call): Likewise.  Move around call to prepare_call_address
and pass all flags to it.
* cfgexpand.c (expand_call_stmt): Reinstate CALL_EXPR_BY_DESCRIPTOR.
* gimple.h (enum gf_mask): New GF_CALL_BY_DESCRIPTOR value.
(gimple_call_set_by_descriptor): New setter.
(gimple_call_by_descriptor_p): New getter.
* gimple.c (gimple_build_call_from_tree): SetCALL_EXPR_BY_DESCRIPTOR.
(gimple_call_flags): Deal with GF_CALL_BY_DESCRIPTOR.
* langhooks.h (struct lang_hooks): Add custom_function_descriptors.
* langhooks-def.h (LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS): Define.
(LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS.
* rtl.h (STATIC_CHAIN_REG_P): New macro.
* rtlanal.c (find_first_parameter_load): Skip static chain registers.
* target.def (custom_function_descriptors): New POD hook.
* tree.h (FUNC_ADDR_BY_DESCRIPTOR): New flag on ADDR_EXPR.
(CALL_EXPR_BY_DESCRIPTOR): New flag on CALL_EXPR.
* tree-core.h (ECF_BY_DESCRIPTOR): New mask.
Document FUNC_ADDR_BY_DESCRIPTOR and CALL_EXPR_BY_DESCRIPTOR.
* tree.c (make_node_stat) : Use FUNCTION_ALIGNMENT.
(build_common_builtin_nodes): Initialize init_descriptor and
adjust_descriptor.
* tree-nested.c: Include target.h.
(struct nesting_info): Add 'any_descr_created' field.
(get_descriptor_type): New function.
(lookup_element_for_decl): New function extracted from...
(create_field_for_decl): Likewise.
(lookup_tramp_for_decl): ...here.  Adjust.
(lookup_descr_for_decl): New function.
(convert_tramp_reference_op): Deal with descriptors.
(build_init_call_stmt): New function extracted from...
(finalize_nesting_tree_1): ...here.  Adjust and deal withdescriptors.
* defaults.h (FUNCTION_ALIGNMENT): Define.
(TRAMPOLINE_ALIGNMENT): Set to above instead of FUNCTION_BOUNDARY.


ANd just to be clear, I'm assuming you'll self-approve the Ada bits :-)

jeff


Re: [patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-09-12 Thread Jeff Law

On 09/04/2016 02:10 PM, Eric Botcazou wrote:

This is the common infrastructure part.  As explained in the initial message,
nothing is activated unless both the language and the target opt in.


2016-07-04  Eric Botcazou  

PR ada/37139
PR ada/67205
* common.opt (-ftrampolines): New option.
* doc/invoke.texi (Code Gen Options): Document it.
* doc/tm.texi.in (Trampolines): AddTARGET_CUSTOM_FUNCTION_DESCRIPTORS
* doc/tm.texi: Regenerate.
* builtins.def: Add init_descriptor and adjust_descriptor.
* builtins.c (expand_builtin_init_trampoline): Do not issue a warning
on platforms with descriptors.
(expand_builtin_init_descriptor): New function.
(expand_builtin_adjust_descriptor): Likewise.
(expand_builtin) : New case.
: Likewise.
* calls.c (prepare_call_address): Remove SIBCALLP parameter and add
FLAGS parameter.  Deal with indirect calls by descriptor and adjust.
Set STATIC_CHAIN_REG_P on the static chain register, if any.
(call_expr_flags): Set ECF_BY_DESCRIPTOR for calls by descriptor.
(expand_call): Likewise.  Move around call to prepare_call_address
and pass all flags to it.
* cfgexpand.c (expand_call_stmt): Reinstate CALL_EXPR_BY_DESCRIPTOR.
* gimple.h (enum gf_mask): New GF_CALL_BY_DESCRIPTOR value.
(gimple_call_set_by_descriptor): New setter.
(gimple_call_by_descriptor_p): New getter.
* gimple.c (gimple_build_call_from_tree): SetCALL_EXPR_BY_DESCRIPTOR.
(gimple_call_flags): Deal with GF_CALL_BY_DESCRIPTOR.
* langhooks.h (struct lang_hooks): Add custom_function_descriptors.
* langhooks-def.h (LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS): Define.
(LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS.
* rtl.h (STATIC_CHAIN_REG_P): New macro.
* rtlanal.c (find_first_parameter_load): Skip static chain registers.
* target.def (custom_function_descriptors): New POD hook.
* tree.h (FUNC_ADDR_BY_DESCRIPTOR): New flag on ADDR_EXPR.
(CALL_EXPR_BY_DESCRIPTOR): New flag on CALL_EXPR.
* tree-core.h (ECF_BY_DESCRIPTOR): New mask.
Document FUNC_ADDR_BY_DESCRIPTOR and CALL_EXPR_BY_DESCRIPTOR.
* tree.c (make_node_stat) : Use FUNCTION_ALIGNMENT.
(build_common_builtin_nodes): Initialize init_descriptor and
adjust_descriptor.
* tree-nested.c: Include target.h.
(struct nesting_info): Add 'any_descr_created' field.
(get_descriptor_type): New function.
(lookup_element_for_decl): New function extracted from...
(create_field_for_decl): Likewise.
(lookup_tramp_for_decl): ...here.  Adjust.
(lookup_descr_for_decl): New function.
(convert_tramp_reference_op): Deal with descriptors.
(build_init_call_stmt): New function extracted from...
(finalize_nesting_tree_1): ...here.  Adjust and deal withdescriptors.
* defaults.h (FUNCTION_ALIGNMENT): Define.
(TRAMPOLINE_ALIGNMENT): Set to above instead of FUNCTION_BOUNDARY.


OK.
jeff



[patch v2] Get rid of stack trampolines for nested functions (1/4)

2016-09-04 Thread Eric Botcazou
This is the common infrastructure part.  As explained in the initial message, 
nothing is activated unless both the language and the target opt in.


2016-07-04  Eric Botcazou  

PR ada/37139
PR ada/67205
* common.opt (-ftrampolines): New option.
* doc/invoke.texi (Code Gen Options): Document it.
* doc/tm.texi.in (Trampolines): AddTARGET_CUSTOM_FUNCTION_DESCRIPTORS
* doc/tm.texi: Regenerate.
* builtins.def: Add init_descriptor and adjust_descriptor.
* builtins.c (expand_builtin_init_trampoline): Do not issue a warning
on platforms with descriptors.
(expand_builtin_init_descriptor): New function.
(expand_builtin_adjust_descriptor): Likewise.
(expand_builtin) : New case.
: Likewise.
* calls.c (prepare_call_address): Remove SIBCALLP parameter and add
FLAGS parameter.  Deal with indirect calls by descriptor and adjust.
Set STATIC_CHAIN_REG_P on the static chain register, if any.
(call_expr_flags): Set ECF_BY_DESCRIPTOR for calls by descriptor.
(expand_call): Likewise.  Move around call to prepare_call_address
and pass all flags to it.
* cfgexpand.c (expand_call_stmt): Reinstate CALL_EXPR_BY_DESCRIPTOR.
* gimple.h (enum gf_mask): New GF_CALL_BY_DESCRIPTOR value.
(gimple_call_set_by_descriptor): New setter.
(gimple_call_by_descriptor_p): New getter.
* gimple.c (gimple_build_call_from_tree): SetCALL_EXPR_BY_DESCRIPTOR.
(gimple_call_flags): Deal with GF_CALL_BY_DESCRIPTOR.
* langhooks.h (struct lang_hooks): Add custom_function_descriptors.
* langhooks-def.h (LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS): Define.
(LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS.
* rtl.h (STATIC_CHAIN_REG_P): New macro.
* rtlanal.c (find_first_parameter_load): Skip static chain registers.
* target.def (custom_function_descriptors): New POD hook.
* tree.h (FUNC_ADDR_BY_DESCRIPTOR): New flag on ADDR_EXPR.
(CALL_EXPR_BY_DESCRIPTOR): New flag on CALL_EXPR.
* tree-core.h (ECF_BY_DESCRIPTOR): New mask.
Document FUNC_ADDR_BY_DESCRIPTOR and CALL_EXPR_BY_DESCRIPTOR.
* tree.c (make_node_stat) : Use FUNCTION_ALIGNMENT.
(build_common_builtin_nodes): Initialize init_descriptor and
adjust_descriptor.
* tree-nested.c: Include target.h.
(struct nesting_info): Add 'any_descr_created' field.
(get_descriptor_type): New function.
(lookup_element_for_decl): New function extracted from...
(create_field_for_decl): Likewise.
(lookup_tramp_for_decl): ...here.  Adjust.
(lookup_descr_for_decl): New function.
(convert_tramp_reference_op): Deal with descriptors.
(build_init_call_stmt): New function extracted from...
(finalize_nesting_tree_1): ...here.  Adjust and deal withdescriptors.
* defaults.h (FUNCTION_ALIGNMENT): Define.
(TRAMPOLINE_ALIGNMENT): Set to above instead of FUNCTION_BOUNDARY.

-- 
Eric BotcazouIndex: builtins.c
===
--- builtins.c	(revision 239944)
+++ builtins.c	(working copy)
@@ -4618,8 +4618,9 @@ expand_builtin_init_trampoline (tree exp, bool ons
 {
   trampolines_created = 1;
 
-  warning_at (DECL_SOURCE_LOCATION (t_func), OPT_Wtrampolines,
-		  "trampoline generated for nested function %qD", t_func);
+  if (targetm.calls.custom_function_descriptors != 0)
+	warning_at (DECL_SOURCE_LOCATION (t_func), OPT_Wtrampolines,
+		"trampoline generated for nested function %qD", t_func);
 }
 
   return const0_rtx;
@@ -4641,6 +4642,58 @@ expand_builtin_adjust_trampoline (tree exp)
   return tramp;
 }
 
+/* Expand a call to the builtin descriptor initialization routine.
+   A descriptor is made up of a couple of pointers to the static
+   chain and the code entry in this order.  */
+
+static rtx
+expand_builtin_init_descriptor (tree exp)
+{
+  tree t_descr, t_func, t_chain;
+  rtx m_descr, r_descr, r_func, r_chain;
+
+  if (!validate_arglist (exp, POINTER_TYPE, POINTER_TYPE, POINTER_TYPE,
+			 VOID_TYPE))
+return NULL_RTX;
+
+  t_descr = CALL_EXPR_ARG (exp, 0);
+  t_func = CALL_EXPR_ARG (exp, 1);
+  t_chain = CALL_EXPR_ARG (exp, 2);
+
+  r_descr = expand_normal (t_descr);
+  m_descr = gen_rtx_MEM (BLKmode, r_descr);
+  MEM_NOTRAP_P (m_descr) = 1;
+
+  r_func = expand_normal (t_func);
+  r_chain = expand_normal (t_chain);
+
+  /* Generate insns to initialize the descriptor.  */
+  emit_move_insn (adjust_address_nv (m_descr, ptr_mode, 0), r_chain);
+  emit_move_insn (adjust_address_nv (m_descr, ptr_mode,
+ POINTER_SIZE / BITS_PER_UNIT), r_func);
+
+  return const0_rtx;
+}
+
+/* Expand a call to the builtin descriptor adjustment routine.  */
+
+static rtx
+expand_builtin_adjust_descriptor (tree exp)
+{
+  rtx tramp;
+
+  if