Re: Reintroduce -mflat option on SPARC

2011-06-10 Thread Eric Botcazou
> Yes, I have changed a few things, patch attached.  The basic stuff works,
> but not yet the fancy features (non-local gotos, setjmp/longjmp and
> exceptions). I'm also working on the GDB side.

I've now installed the attached version.  It adds support for the above fancy 
features plus sibling calls, frame pointer elimination and 64-bit code in flat 
mode.  I'll submit the associated GDB patch sometime next week.

It also contains a few changes for the regular mode:
 - %fp isn't a fixed register anymore,
 - EXIT_IGNORE_STACK is defined to 1 unconditionally,
 - __builtin_eh_return is more correctly implemented,
 - sparc_legitimate_address_p was wrongly rejecting offsettable addresses when 
the offset was too close to 4095.

Bootstrapped/regtested on SPARC/Solaris and SPARC64/Solaris.  The C testsuite 
is 100% clean in flat mode; for the others, you need at least -mflat multlibs.


2011-06-10  Eric Botcazou  
Laurent Rougé  

* doc/invoke.texi (SPARC options): Add -mflat.
* config/sparc/sparc.opt: Likewise.
* config/sparc/sparc-protos.h (sparc_expand_epilogue): Add parameter.
(sparc_flat_expand_prologue): Declare.
(sparc_flat_expand_epilogue): Likewise.
* config/sparc/sparc.h (CPP_CPU_SPEC): Do not handle -msoft-float.
(CPP_ENDIAN_SPEC): Replace with...
(CPP_OTHER_SPEC): ...this.  Also handle -mflat and -msoft-float.
(CPP_SPEC): Adjust to above change.
(EXTRA_SPECS): Likewise.
(SPARC_INCOMING_INT_ARG_FIRST): Add TARGET_FLAT handling.
(INCOMING_REGNO): Likewise.
(OUTGOING_REGNO): Likewise.
(LOCAL_REGNO): Likewise.
(SETUP_FRAME_ADDRESSES): Likewise.
(FIXED_REGISTERS): Set 0 for %fp.
(CALL_USED_REGISTERS): Likewise.
(INITIAL_ELIMINATION_OFFSET): Pass current_function_is_leaf.
(EXIT_IGNORE_STACK): Define to 1 unconditionally.
(RETURN_ADDR_REGNUM): Define.
(RETURN_ADDR_RTX): Use it.
(INCOMING_RETURN_ADDR_REGNUM): Define.
(INCOMING_RETURN_ADDR_RTX): Use it.
(DWARF_FRAME_RETURN_COLUMN): Likewise.
(EH_RETURN_REGNUM): Define.
(EH_RETURN_STACKADJ_RTX): Use it.
(EH_RETURN_HANDLER_RTX): Delete.
(EPILOGUE_USES): Use them and add TARGET_FLAT handling.
* config/sparc/sparc.c (apparent_fsize, actual_fsize, num_gfregs):
Delete.
(struct machine_function): Add frame_size, apparent_frame_size,
frame_base_reg, frame_base_offset, n_global_fp_regs and
save_local_in_regs_p fields.
(sparc_frame_size, sparc_apparent_frame_size, sparc_frame_base_reg,
sparc_frame_base_offset, sparc_n_global_fp_regs,
sparc_save_local_in_regs_p): New macros.
(sparc_option_override): Error out if -fcall-saved-REG is specified
for Out registers.
(eligible_for_restore_insn): Fix formatting.
(eligible_for_return_delay): Likewise.  Add TARGET_FLAT handling.
(eligible_for_sibcall_delay): Likewise.
(RTX_OK_FOR_OFFSET_P, RTX_OK_FOR_OLO10_P): Add MODE parameter.
(sparc_legitimate_address_p): Adjust to above change.
(save_global_or_fp_reg_p): New predicate.
(return_addr_reg_needed_p): Likewise.
(save_local_or_in_reg_p): Likewise.
(sparc_compute_frame_size): Use them.  Add TARGET_FLAT handling.
(SORR_SAVE, SORR_RESTORE): Delete.
(sorr_pred_t): New typedef.
(sorr_act_t): New enum.
(save_or_restore_regs): Rename to...
(emit_save_or_restore_regs): ...this.  Change type of LOW and HIGH
parameters, remove ACTION parameter, add LEAF_FUNCTION_P, SAVE_P,
ACTION_TRUE and ACTION_FALSE parameters.  Implement more general
mechanism.  Add CFI information for double-word saves in 32-bit mode.
(emit_adjust_base_to_offset): New function extracted from...
(emit_save_or_restore_regs): ...this.  Rename the rest to...
(emit_save_or_restore_regs_global_fp_regs): ...this.
(emit_save_or_restore_regs_local_in_regs): New function.
(gen_create_flat_frame_[123]): New functions.
(sparc_expand_prologue): Use SIZE local variable.  Adjust.
(sparc_flat_expand_prologue): New function.
(sparc_asm_function_prologue): Add TARGET_FLAT handling.
(sparc_expand_epilogue): Use SIZE local variable.  Adjust.
(sparc_flat_expand_epilogue): New function.
(sparc_can_use_return_insn_p): Add TARGET_FLAT handling.
(output_return): Likewise.
(output_sibcall): Likewise.
(sparc_output_mi_thunk): Likewise.
(sparc_frame_pointer_required): Likewise.
(sparc_conditional_register_usage): If TARGET_FLAT, disable the leaf
function optimization.
* config/sparc/sparc.md (flat): New attribute.
(prologue): Add TARGET_FLAT handling.
(save_register_window): Disable if TARGET_FLAT.
(create_flat_frame_[123]): New patterns.

Re: Reintroduce -mflat option on SPARC

2011-05-26 Thread Eric Botcazou
> In fact, I haven't tried to make big changes in how mflat option was
> implemented. From my point of view, the goal was to facilitate mflat
> option reintroduction first, and then improve it after. I hope you
> understand. I know there's some place to improve, maybe you have start
> to do it ?

Yes, I have changed a few things, patch attached.  The basic stuff works, but 
not yet the fancy features (non-local gotos, setjmp/longjmp and exceptions).  
I'm also working on the GDB side.

> So why mflat is like that we should ask the questions to 'wilson' who
> did it in 92 (see revision 1275) !

Indeed, thanks for doing the archaeology. :-)


* doc/invoke.texi (SPARC options): Add -mflat.
* config/sparc/sparc.opt: Likewise.
* config/sparc/sparc-protos.h (sparc_flat_expand_prologue): Declare.
(sparc_flat_expand_epilogue): Likewise.
(load_got_register): Likewise.
* config/sparc/sparc.h (CPP_CPU_SPEC): Define _FLAT in flat mode.
(SPARC_INCOMING_INT_ARG_FIRST): Add TARGET_FLAT handling.
(INCOMING_REGNO): Likewise.
(OUTGOING_REGNO): Likewise.
(LOCAL_REGNO): Likewise.
(FIXED_REGISTERS): Set 0 for %fp.
(CALL_USED_REGISTERS): Likewise.
(RETURN_ADDR_REGNUM): Define.
(RETURN_ADDR_RTX): Use it.
(EH_RETURN_HANDLER_RTX): Use it.
(INCOMING_RETURN_ADDR_REGNUM): Define.
(INCOMING_RETURN_ADDR_RTX): Use it.
(DWARF_FRAME_RETURN_COLUMN): Likewise.
(EH_RETURN_REGNUM): Define.
(EH_RETURN_STACKADJ_RTX): Use it.
(EPILOGUE_USES): Use them and add TARGET_FLAT handling.
* config/sparc/sparc.c (struct machine_function): Add frame_size,
apparent_frame_size, frame_base_reg, frame_base_offset, n_regs
and save_local_in_regs_p fields.
(sparc_frame_size, sparc_apparent_frame_size, sparc_frame_base_reg,
sparc_frame_base_offset, sparc_n_regs, sparc_save_local_in_regs_p):
New macros.
(sparc_option_override): Error out if -fcall-saved-REG is specified
for Out registers.
(eligible_for_restore_insn): Fix formatting.
(eligible_for_return_delay): Likewise.  Add TARGET_FLAT handling.
(load_got_register): Make global.
(save_global_or_fp_reg_p): New predicate.
(incoming_return_addr_reg_clobbered_p): Likewise.
(save_local_or_in_reg_p): Likewise.
(sparc_compute_frame_size): Use them.  Add TARGET_FLAT handling.
(SORR_SAVE, SORR_RESTORE): Delete.
(sorr_pred_t): New typedef.
(sorr_act_t): New enum.
(save_or_restore_regs): Rename to...
(emit_save_or_restore): ...this.  Changed type of LOW/HIGH parameters
remove ACTION parameter, add LEAF_FUNCTION_P, SAVE_P, ACTION_TRUE and
ACTION_FALSE parameters.  Implement more general mechanism.  Add CFI
information for double-word saves in 32-bit mode.
(emit_adjust_base_to_offset): New function extracted from...
(emit_save_or_restore_regs): ...this.  Rename the rest to...
(emit_save_or_restore_regs_global_fp_regs): ...this.
(emit_save_or_restore_regs_local_in_regs): New function.
(gen_create_flat_frame_[123]): New functions.
(sparc_expand_prologue): Use SIZE local variable.  Adjust.
(sparc_flat_expand_prologue): New function.
(sparc_asm_function_prologue): Add TARGET_FLAT handling.
(sparc_expand_epilogue): Use SIZE local variable.  Adjust.
(sparc_flat_expand_epilogue): New function.
(sparc_can_use_return_insn_p):  Add TARGET_FLAT handling.
(output_return): Likewise.
(sparc_function_ok_for_sibcall): Likewise.
(sparc_frame_pointer_required): Likewise.
(sparc_can_eliminate): Call sparc_frame_pointer_required directly.
(sparc_conditional_register_usage): If TARGET_FLAT, disable leaf
function optimization.
* config/sparc/sparc.md (flat): New attribute.
(prologue): Add TARGET_FLAT handling.
(epilogue): Likewise.
(sibcall_epilogue): Likewise.
(save_register_window): Disable if TARGET_FLAT.
(create_flat_frame_[123]): New patterns.
(return_internal): Add TARGET_FLAT handling.
(flush_register_windows): Likewise.
(goto_handler_and_restore): Likewise.
(exception_receiver): New pattern.
(builtin_setjmp_receiver): Likewise.


-- 
Eric Botcazou


gcc-4.7-mflat-2.diff.gz
Description: GNU Zip compressed data


Re: Reintroduce -mflat option on SPARC

2011-05-26 Thread Laurent Rougé
Dear Eric,

In fact, I haven't tried to make big changes in how mflat option was
implemented. From my point of view, the goal was to facilitate mflat
option reintroduction first, and then improve it after. I hope you
understand. I know there's some place to improve, maybe you have start
to do it ?

So why mflat is like that we should ask the questions to 'wilson' who
did it in 92 (see revision 1275) !

Regards,
Laurent.

Le 18/05/2011 12:31, Eric Botcazou a écrit :
>> Another question: why does the model hijack %i7 to use it as frame pointer,
>> instead of just using %fp?  AFAICS both are kept as fixed registers by the
>> code so the model seems to be wasting 1 register (2 without frame pointer).
> Related question: why saving the Local and In registers in the frame instead 
> of 
> at their standard location, right above the stack pointer?  It would seem to 
> me that the layout of the frame can be identical to the standard one.



Re: Reintroduce -mflat option on SPARC

2011-05-18 Thread Eric Botcazou
> Another question: why does the model hijack %i7 to use it as frame pointer,
> instead of just using %fp?  AFAICS both are kept as fixed registers by the
> code so the model seems to be wasting 1 register (2 without frame pointer).

Related question: why saving the Local and In registers in the frame instead of 
at their standard location, right above the stack pointer?  It would seem to 
me that the layout of the frame can be identical to the standard one.

-- 
Eric Botcazou


Re: Reintroduce -mflat option on SPARC

2011-05-17 Thread Eric Botcazou
> Right, -mflat option should only be for 32-bit SPARC target.

OK, let's keep it that way for now.

Another question: why does the model hijack %i7 to use it as frame pointer, 
instead of just using %fp?  AFAICS both are kept as fixed registers by the 
code so the model seems to be wasting 1 register (2 without frame pointer).

-- 
Eric Botcazou


Re: Reintroduce -mflat option on SPARC

2011-04-14 Thread Laurent Rougé

>> This patch reintroduce the -mflat option on SPARC. The -mfalt option was
>> deprecated in february 2004 with GCC 3.4.6. Now, with the support of
>> LEON processor on GCC, this option has found a new interest.
> Just a couple of remarks:
>  - the epilogue isn't fully RTL-ized,
>  - delay slot filling for epilogue doesn't work: DELAY_SLOTS_FOR_EPILOGUE 
> isn't 
> defined anymore so defining ELIGIBLE_FOR_EPILOGUE_DELAY is useless.
>
> I'm going to fix these minor issues, as well as try to refactor the code a 
> bit.

Please, it will be interesting to see corrections.

> One question: I presume there is no point in supporting -mflat in 64-bit mode 
> for the time being?

Right, -mflat option should only be for 32-bit SPARC target.

Regards,
Laurent.



Re: Reintroduce -mflat option on SPARC

2011-04-12 Thread Eric Botcazou
> This patch reintroduce the -mflat option on SPARC. The -mfalt option was
> deprecated in february 2004 with GCC 3.4.6. Now, with the support of
> LEON processor on GCC, this option has found a new interest.

Just a couple of remarks:
 - the epilogue isn't fully RTL-ized,
 - delay slot filling for epilogue doesn't work: DELAY_SLOTS_FOR_EPILOGUE isn't 
defined anymore so defining ELIGIBLE_FOR_EPILOGUE_DELAY is useless.

I'm going to fix these minor issues, as well as try to refactor the code a bit.

One question: I presume there is no point in supporting -mflat in 64-bit mode 
for the time being?

-- 
Eric Botcazou