Re: Jumps across functions



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.


.



Relevant Pages

  • Re: Looking for a free basic compiler for DOS
    ... BC for 7.1 had a lot of compiler switchable options, ... NEVER compile from the ide. ... One trivial example: I have a routine declared as: ... were no manuals, just a readme file. ...
    (comp.lang.basic.misc)
  • Re: SAMBA for VMS (The saga continues!)
    ... > callee (substitute function) code seems small to me. ... determine that the OS routine is now available. ... >>instructions and also disabling the compiler optimizer that you can rely ... they upgrade VMS and then try to install an existing package. ...
    (comp.os.vms)
  • Generic Maze Program Example 1
    ... This is the DOS DPMI version of the compiler in Rick van Norman's ... The original code for this was done by Larry Myers, ... routine that Larry used. ... press the #5 key on the numeric keypad. ...
    (comp.lang.forth)
  • Re: SAMBA for VMS (The saga continues!)
    ... Because it is the only way to prevent conflicts with the compiler ... optimizer and with shared images that may be loaded on any platform. ... This is the case on some modern UNIX platforms and especially on OpenVMS ... they were reserved names as far as global routine names are concerned. ...
    (comp.os.vms)
  • Re: Problem with Return Value from a Function
    ... It was always possible to write an assembly language routine that could be called from PL/I as a function and the location to receive the returned value was passed by reference as an n+1st argument. ... Function references to assembler routines were only possible if the ASSEMBLER option was *not* used, thus the compiler was unaware the the routine being called was an assembler routine and perforce must have compiled the same linkage it would compile when it was calling a routine written in PL/I. ... but I agree that not assigning at all would ...
    (comp.lang.pl1)