[patch,avr] Fix PR20296 / PR81268: Better ISR prologues / epilogues

Georg-Johann Lay avr@gjlay.de
Fri Jul 7 14:31:00 GMT 2017


Hi,

this patch addresses a very old issue, the non-optimal
generation of ISR prologues and epilogues.

As GAS now provides the __gcc_isr pseudo instruction to
overcome some problems, see

https://sourceware.org/bugzilla/show_bug.cgi?id=21683

this can now be used to address PR20296.


This patch does:

* Add a configure test if GAS supports __gcc_isr and -mgcc-isr.

* Add new option -mgas-isr-prologues to switch on / off
   generating of __gcc_isr in ISR prologues / epilogues.

* Switch on the feature per default except for -O0 and -Og.

* Add a new no_gccisr function attribute to disable __gcc_isr
   generation for individual ISRs.

* Add a new pass .avr-gasisr that filters out situations where
   __gcc_isr is not appropriate.

* Extend prologue and epilogue generation to emit __gcc_isr chunks
   during prologue and epilogue(s).

* Implement final_postscan_insn to emit final __gcc_isr Done chunk.

* Add -mgcc-isr to ASM_SPEC if appropriate.


We currently have only 3 torture tests for ISRs, namely

gcc.target/avr/torture/isr-*.c

All these tests PASS when

* Run with -mgas-isr-prologues
* Run with -mno-gas-isr-prologues
* Run for: atmega8 atmega64 atmega103 atmega2560 atmega128 atxmega128a1 
attiny40

Ok for trunk?

Johann

	PR target/20296
	PR target/81268
	* configure.ac [target=avr]: Add GAS check for -mgcc-isr.
	(HAVE_AS_AVR_MGCCISR_OPTION):  If so, AC_DEFINE it.
	* config.in: Regenerate.
	* configure: Regenerate.

	* doc/extend.texi (AVR Function Attributes) <no_gccisr>: Document it.
	* doc/invoke.texi (AVR Options) <-mgas-isr-prologues>: Document it.

	* config/avr/avr.opt (-mgas-isr-prologues): New option and...
	(TARGET_GASISR_PROLOGUES): ...target mask.
	* common/config/avr/avr-common.c
	(avr_option_optimization_table) [OPT_LEVELS_1_PLUS_NOT_DEBUG]:
	Set -mgas-isr-prologues.
	* config/avr/avr-passes.def (avr_pass_maybe_gasisr): Add
	INSERT_PASS_BEFORE for it.
	* config/avr/avr-protos.h (make_avr_pass_maybe_gasisr): New proto.
	* config/avr/avr.c (avr_option_override)
	[!HAVE_AS_AVR_MGCCISR_OPTION]: Unset TARGET_GASISR_PROLOGUES.
	(avr_no_gccisr_function_p, avr_hregs_split_lsb): New static functions.
	(avr_attribute_table) <no_gccisr>: Add new function attribute.
	(avr_set_current_function) <is_no_gccisr>: Init machine field.
	(avr_pass_data_gasisr, avr_pass_maybe_gasisr): New pass data
	and rtl_opt_pass.
	(make_avr_pass_maybe_gasisr): New function.
	(emit_push_sfr) <treg>: Add argument to function and use it
	instead of TMP_REG.
	(avr_expand_prologue) [machine->gasisr.maybe]: Emit gasisr insn
	and set machine->gasisr.yes.
	(avr_expand_epilogue) [machine->gasisr.yes]: Similar.
	(avr_asm_function_end_prologue) [machine->gasisr.yes]: Add
	__gcc_isr.n_pushed to .L__stack_usage.
	(TARGET_ASM_FINAL_POSTSCAN_INSN): Define to...
	(avr_asm_final_postscan_insn): ...this new static function.
	* config/avr/avr.h (machine_function)
	<is_no_gccisr, use_L__stack_usage>: New fields.
	<gasisr, gasisr.yes, gasisr.maybe, gasisr.regno>: New fields.
	* config/avr/avr.md (UNSPECV_GASISR): Add unspecv enum.
	(GASISR_Prologue, GASISR_Epilogue, GASISR_Done): New define_constants.
	(gasisr, *gasisr): New expander and insn.
	* config/avr/gen-avr-mmcu-specs.c (print_mcu)
	[HAVE_AS_AVR_MGCCISR_OPTION]: Print asm_gccisr spec.
	* config/avr/specs.h (ASM_SPEC) <asm_gccisr>: Add sub spec.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr81268-gccisr.diff
Type: text/x-patch
Size: 28494 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170707/6b763660/attachment.bin>


More information about the Gcc-patches mailing list