A leaf routine, leaf subroutine, leaf function, or leaf procedure is a function that does not in turn call another function. Some compilers can apply special program optimizations to leaf routines to make them more efficient, such as the use of link registers to avoid having to push the return address on the stack, or not allocating a register window on CPU architectures descended from Berkeley RISC.[1]

The term "leaf" refers to their position as leaf nodes in the call graph of the program.

Usually, most non-leaf routines call more than one other function. When this is the case, the majority of function calls in the call graph are calls to leaf routines, because a binary tree has more leaf nodes than non-leaf nodes (assuming that all non-leaf nodes have two children). Consequently, the efficiency of calls to leaf routines often has a significant effect on the efficiency of the whole program.[citation needed]

References

edit
  1. ^ "Leaf Functions (GCC (GNU Compiler Collection) Internals Manual)".


📚 Artikel Terkait di Wikipedia

Function (computer programming)

In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-formed

Link register

general-purpose register, allows for faster calls to leaf subroutines. When the subroutine is non-leaf, passing the return address in a register can still

Tail call

tail call is a subroutine call performed as the final action of a procedure. If the target of a tail is the same subroutine, the subroutine is said to be

Tree (abstract data type)

visualized in an exploded-view drawing Subroutine calls used to identify which subroutines in a program call other subroutines non recursively Inheritance of

Calling convention

calling convention is an implementation-level (low-level) scheme for how subroutines or functions receive parameters from their caller and how they return

Raku (programming language)

counting and some type checking can be done using Perl's "prototypes"). Subroutine arguments passed in are aliased into the elements of the array @_. If

X86 calling conventions

push 1 call callee ; call subroutine 'callee' add esp, 12 ; remove call arguments from frame add eax, 5 ; modify subroutine result ; (eax is the return

RISC-V

are good candidates to fuse with jalr, addi, loads or stores. RISC-V's subroutine call jal (jump and link) places its return address in a register. This