CALLER_SAVE/RESTORE in CCalls
Simon Marlow
simonmar@microsoft.com
Wed, 21 Mar 2001 10:53:09 -0000
Hi Sven, welcome back :)
> ...
> CALLER_SAVE_SYSTEM
> {
> StgFloat _ccall_arg1=3D(StgFloat)0.75;
> StgFloat _ccall_arg2=3D(StgFloat)0.25;
> StgFloat _ccall_arg3=3D(StgFloat)0.0;
> (glVertex3f((_ccall_arg1),(_ccall_arg2),(_ccall_arg3)));
> }
> CALLER_RESTORE_SYSTEM // !!!
> CALLER_SAVE_SYSTEM // !!!
> {
> StgFloat _ccall_arg1=3D(StgFloat)0.75;
> StgFloat _ccall_arg2=3D(StgFloat)0.75;
> StgFloat _ccall_arg3=3D(StgFloat)0.0;
> (glVertex3f((_ccall_arg1),(_ccall_arg2),(_ccall_arg3)));
> }
> CALLER_RESTORE_SYSTEM
> ...
>=20
> gcc is/was clever enough to omit the code for the marked=20
> lines. Changing
> this in PprAbsC looks easy, or do I miss something here?
Well, arguably the current version is more correct, since the ccall
arguments might refer to certain STG registers. However, it shouldn't
do any harm to re-order things as you suggest.
> And a related question: What's the reason for the local vars=20
> in the above
> calls? The following looks a bit simpler:
> ...
> CALLER_SAVE_SYSTEM
> glVertex3f(((StgFloat)0.75, (StgFloat)0.25, (StgFloat)0.0);
> CALLER_RESTORE_SYSTEM // !!!
> CALLER_SAVE_SYSTEM // !!!
> glVertex3f(((StgFloat)0.75, (StgFloat)0.75, (StgFloat)0.0);
> CALLER_RESTORE_SYSTEM
> ...
>=20
> Apart from that, the generated code looks quite cool.
I think the reason for putting the arguments into local vars is for
casms: if a casm refers to a particular arg twice, for example, it won't
duplicate the expression.
Cheers,
Simon