Re: Jumps across functions
- From: Gene <gene.ressler@xxxxxxxxx>
- Date: Tue, 28 Aug 2007 01:27:22 -0000
On Aug 27, 6:50 pm, dj3va...@xxxxxxxxxxxxxxxxxxx (Dave Vandervies)
wrote:
In article <5jh0qcF3rroh...@xxxxxxxxxxxxxxxxxx>,
Tim Frink <plfr...@xxxxxxxx> wrote:
Hi,
is is possible to get valid assembler code from a
C source code with jumps from one routine
to a basic block in another routine?
Example:
routine main
.L1 ... // Labels for basic blocks
.L2 ...
routine foo
.L3
.L4
Can I have a jump from basic block L1 to basic block
L3?
The compiler can do anything it wants, as long as correct input results
in generated code that behaves appropriately.
One example of where a realistic compiler might actually do this is
"inlining" a tail-call:
Input code of this form:
--------
int foo(void)
{
/*do foo here*/
return result;
}
int main(void)
{
/*do setup here*/
if(success)
return foo();
else
return EXIT_FAILURE;}
--------
could produce output of this form:
--------
routine foo
.L1
; do foo here
ret
routine main
;do setup here
jnz L1 ;tail-call to foo() if successfully initialized
;load failure return status here
ret
--------
Another is common tail code merging:
SOME_TYPE foo(...)
{
// yada yada yada
// basic block A
}
SOME_TYPE bar(...)
{
// yada yada yada different from above
// basic block A again
}
Basic block A need only exist in one place. It "belongs" to both
routines.
This optimization is important if code memory is at a premium. E.g.
old Borland compilers for DOS used it (64K code segments), and I
wouldn't be surprised to find it in compilres for small
microcontrollers.
On the other hand, dataflow-based "global" optimizations and
instruction reordering make it less likely that tail machine codes
will be identical even if tail source codes are.
.
- References:
- Jumps across functions
- From: Tim Frink
- Re: Jumps across functions
- From: Dave Vandervies
- Jumps across functions
- Prev by Date: Re: Jumps across functions
- Next by Date: efficient comparison
- Previous by thread: Re: Jumps across functions
- Next by thread: Re: Jumps across functions
- Index(es):
Relevant Pages
|