Skip to content
Snippets Groups Projects
Commit 71f90649 authored by Andrew Waterman's avatar Andrew Waterman Committed by Jeff Law
Browse files

RISC-V: far-branch: Handle far jumps and branches for functions larger than 1MB


On RISC-V, branches further than +/-1MB require a longer instruction
sequence (3 instructions): we can reuse the jump-construction in the
assmbler (which clobbers $ra) and a temporary to set up the jump
destination.

gcc/ChangeLog:

	* config/riscv/riscv.cc (struct machine_function): Track if a
	far-branch/jump is used within a function (and $ra needs to be
	saved).
	(riscv_print_operand): Implement 'N' (inverse integer branch).
	(riscv_far_jump_used_p): Implement.
	(riscv_save_return_addr_reg_p): New function.
	(riscv_save_reg_p): Use riscv_save_return_addr_reg_p.
	* config/riscv/riscv.h (FIXED_REGISTERS): Update $ra.
	(CALL_USED_REGISTERS): Update $ra.
	* config/riscv/riscv.md: Add new types "ret" and "jalr".
	(length attribute): Handle long conditional and unconditional
	branches.
	(conditional branch pattern): Handle case where jump can not
	reach the intended target.
	(indirect_jump, tablejump): Use new "jalr" type.
	(simple_return): Use new "ret" type.
	(simple_return_internal, eh_return_internal): Likewise.
	(gpr_restore_return, riscv_mret): Likewise.
	(riscv_uret, riscv_sret): Likewise.
	* config/riscv/generic.md (generic_branch): Also recognize jalr & ret
	types.
	* config/riscv/sifive-7.md (sifive_7_jump): Likewise.

Co-authored-by: default avatarPhilipp Tomsich <philipp.tomsich@vrull.eu>
Co-authored-by: default avatarJeff Law <jlaw@ventanamicro.com>
parent bd5719bd
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment