CALLER_SAVE/RESTORE in CCalls
Sven Panne
Sven.Panne@informatik.uni-muenchen.de
Tue, 20 Mar 2001 23:43:40 +0100
Currently the C code generated for consecutive CCalls is something like that
(taken from HOpenGL examples, what else? :-):
...
{
StgFloat _ccall_arg1=(StgFloat)0.75;
StgFloat _ccall_arg2=(StgFloat)0.25;
StgFloat _ccall_arg3=(StgFloat)0.0;
CALLER_SAVE_SYSTEM
(glVertex3f((_ccall_arg1),(_ccall_arg2),(_ccall_arg3)));
CALLER_RESTORE_SYSTEM
}
{
StgFloat _ccall_arg1=(StgFloat)0.75;
StgFloat _ccall_arg2=(StgFloat)0.75;
StgFloat _ccall_arg3=(StgFloat)0.0;
CALLER_SAVE_SYSTEM
(glVertex3f((_ccall_arg1),(_ccall_arg2),(_ccall_arg3)));
CALLER_RESTORE_SYSTEM
}
...
This is a bit unfortunate, because this way gcc is unable to nuke no-op
CALLER_RESTORE_SYSTEM/CALLER_SAVE_SYSTEM pairs. I 'm quite sure that
the code in the good old times for this was something like:
...
CALLER_SAVE_SYSTEM
{
StgFloat _ccall_arg1=(StgFloat)0.75;
StgFloat _ccall_arg2=(StgFloat)0.25;
StgFloat _ccall_arg3=(StgFloat)0.0;
(glVertex3f((_ccall_arg1),(_ccall_arg2),(_ccall_arg3)));
}
CALLER_RESTORE_SYSTEM // !!!
CALLER_SAVE_SYSTEM // !!!
{
StgFloat _ccall_arg1=(StgFloat)0.75;
StgFloat _ccall_arg2=(StgFloat)0.75;
StgFloat _ccall_arg3=(StgFloat)0.0;
(glVertex3f((_ccall_arg1),(_ccall_arg2),(_ccall_arg3)));
}
CALLER_RESTORE_SYSTEM
...
gcc is/was clever enough to omit the code for the marked lines. Changing
this in PprAbsC looks easy, or do I miss something here?
And a related question: What's the reason for the local vars 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
...
Apart from that, the generated code looks quite cool.
Cheers,
Sven "back-at-the-bleeding-edge" P.