gccint: Leaf Functions
1
1 18.7.4 Handling Leaf Functions
1 ------------------------------
1
1 On some machines, a leaf function (i.e., one which makes no calls) can
1 run more efficiently if it does not make its own register window. Often
1 this means it is required to receive its arguments in the registers
1 where they are passed by the caller, instead of the registers where they
1 would normally arrive.
1
1 The special treatment for leaf functions generally applies only when
1 other conditions are met; for example, often they may use only those
1 registers for its own variables and temporaries. We use the term "leaf
1 function" to mean a function that is suitable for this special handling,
1 so that functions with no calls are not necessarily "leaf functions".
1
1 GCC assigns register numbers before it knows whether the function is
1 suitable for leaf function treatment. So it needs to renumber the
1 registers in order to output a leaf function. The following macros
1 accomplish this.
1
1 -- Macro: LEAF_REGISTERS
1 Name of a char vector, indexed by hard register number, which
1 contains 1 for a register that is allowable in a candidate for leaf
1 function treatment.
1
1 If leaf function treatment involves renumbering the registers, then
1 the registers marked here should be the ones before
1 renumbering--those that GCC would ordinarily allocate. The
1 registers which will actually be used in the assembler code, after
1 renumbering, should not be marked with 1 in this vector.
1
1 Define this macro only if the target machine offers a way to
1 optimize the treatment of leaf functions.
1
1 -- Macro: LEAF_REG_REMAP (REGNO)
1 A C expression whose value is the register number to which REGNO
1 should be renumbered, when a function is treated as a leaf
1 function.
1
1 If REGNO is a register number which should not appear in a leaf
1 function before renumbering, then the expression should yield -1,
1 which will cause the compiler to abort.
1
1 Define this macro only if the target machine offers a way to
1 optimize the treatment of leaf functions, and registers need to be
1 renumbered to do this.
1
1 'TARGET_ASM_FUNCTION_PROLOGUE' and 'TARGET_ASM_FUNCTION_EPILOGUE' must
1 usually treat leaf functions specially. They can test the C variable
1 'current_function_is_leaf' which is nonzero for leaf functions.
1 'current_function_is_leaf' is set prior to local register allocation and
1 is valid for the remaining compiler passes. They can also test the C
1 variable 'current_function_uses_only_leaf_regs' which is nonzero for
1 leaf functions which only use leaf registers.
1 'current_function_uses_only_leaf_regs' is valid after all passes that
1 modify the instructions have been run and is only useful if
1 'LEAF_REGISTERS' is defined.
1