Function Duplication
Jump to navigation
Jump to search
A function duplication transformation also known as function cloning is a technique commonly used in program optimization, parallelization, and analysis to create multiple copies of a function, each tailored to a specific context or use case. This approach allows for greater flexibility in optimizing or analyzing the function based on how it's used.
Description
Function duplication copies an existing function every time the function is called from a different part of the code. Each copy is marked with a _duplicate_<n> suffix to show that multiple versions of the function exist. The additional copies allow individual analysis like constant propagation for each time the function is called.
When is it applied
- When a function is not marked as inline. However, functions called from inline functions may still be copied if all other conditions are met.
- When a function is called more than once
- When the implementation of a function is available
- When the function call is on the call graph started by the root function. Additional calls from functions which are not part of this call graph don't cause any additional copies.
Where is it useful
- Static performance estimation of each call allows for more accurate estimation with its context (parameters and their values, memory usage...)
- Parallelization on different uses depending on the load of all cores during the call
- In combination with constant propagation it can provide improved results for the dependency analysis