SH2A: "RTV/N Rn" implementation

Rask Ingemann Lambertsen rask@sygehus.dk
Tue Jul 17 09:45:00 GMT 2007


On Tue, Jul 17, 2007 at 01:12:19PM +0530, Naveen H.S. wrote:
> Hi,
> 
> RTV/N instruction is one of the new instructions added in the SH2A
> target.
> 
> Description : RTV/N instruction performs a return from a subroutine 
> procedure after a transfer from specified general register Rn to R0.
> That is, after the Rn value is stored in R0, the PC is restored from 
> PR, and processing is resumed from the address indicated by the PC.
> 
> RTV/N		Rn = Rn--->R0 + RTS/N
> So RTV/N instruction can be used as an optimized return instruction 
> in case of the functions having the return type as INTEGER_TYPE. This
> instruction moves the return argument of the function from register 
> Rn--->R0 along with RETURN. So there is no need to exclusively 
> transfer the RETURN value of the function to RETURN_REG (R0) before
> RETURN.
[snip]
> Any help in implementing this instruction would be highly appreciated.

   Presumably the main problem here is that combine runs before the epilogue
is emitted, leaving no chance for combine to generate RTV/N?

   My first shot at this would be to emit RTV/N in a dummy form as part of
the epilogue and leave the usual Rn--->R0 setup as it is, producing

(set (reg R0) (reg Rn))
...
(parallel [
	(set (reg R0) (reg R0))
	(return)
])

and hope that the rnreg pass changes this to

(set (reg R0) (reg Rn))
...
(parallel [
	(set (reg R0) (reg Rn))
	(return)
])

at which point the first instruction becomes dead and we should get just

(parallel [
	(set (reg R0) (reg Rn))
	(return)
])

which is the RTV/N instruction.

   Actually, this is something the register allocator should get right, but
that doesn't seem to happen any time soon.

-- 
Rask Ingemann Lambertsen



More information about the Gcc mailing list