Inline Transformation: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 7: Line 7:
When a function call is inlined, the compiler treats the function much like a code snippet to be substituted into the caller. It will evaluate and assign the function’s arguments to local temporaries (as it would for a normal call), then insert the entire function body at the call site, adjusting variable references and control flow as needed. This means that the normal process of jumping to the function’s code and then returning is bypassed. Ordinarily, a function call requires a branch (transfer of control) to the function, plus setup and teardown instructions (such as saving registers, pushing arguments, and later restoring registers on return) – with inlining, these steps are eliminated so that execution “drops through” directly into the inlined code without a call or return instruction.
When a function call is inlined, the compiler treats the function much like a code snippet to be substituted into the caller. It will evaluate and assign the function’s arguments to local temporaries (as it would for a normal call), then insert the entire function body at the call site, adjusting variable references and control flow as needed. This means that the normal process of jumping to the function’s code and then returning is bypassed. Ordinarily, a function call requires a branch (transfer of control) to the function, plus setup and teardown instructions (such as saving registers, pushing arguments, and later restoring registers on return) – with inlining, these steps are eliminated so that execution “drops through” directly into the inlined code without a call or return instruction.


<ref>C Programming Techniques: Function Call Inlining - Fabien Le Mentec https://www.embeddedrelated.com/showarticle/172.php</ref> ''Function call overhead.'' A normal function call introduces extra instructions for saving state, passing arguments, the call itself, and restoring state after returning (overhead shown in red) separate from the function’s useful computation (blue).
<ref name="Fabien">C Programming Techniques: Function Call Inlining - Fabien Le Mentec https://www.embeddedrelated.com/showarticle/172.php</ref> ''Function call overhead.'' A normal function call introduces extra instructions for saving state, passing arguments, the call itself, and restoring state after returning (overhead shown in red) separate from the function’s useful computation (blue).


<ref>C Programming Techniques: Function Call Inlining - Fabien Le Mentec https://www.embeddedrelated.com/showarticle/172.php</ref> ''Inline expansion removes overhead.'' After inlining, the function’s code is substituted at the call site, so the call and its prologue/epilogue overhead are removed (the red overhead boxes are gone). The program continues executing the inlined body as if it were part of the caller.
<ref name="Fabien"/> ''Inline expansion removes overhead.'' After inlining, the function’s code is substituted at the call site, so the call and its prologue/epilogue overhead are removed (the red overhead boxes are gone). The program continues executing the inlined body as if it were part of the caller.


Because the function body is now part of the caller, the compiler can optimize across what was once a call boundary. For example, if certain arguments are constants at the call site, those constant values may propagate into the inlined function, allowing the compiler to simplify calculations or remove branches inside the function <ref>Inline - Using the GNU Compiler Collection (GCC) https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Inline.html</ref>. In effect, inlining can make two separate functions behave as one larger function, which often enables additional compiler optimizations that would not be possible otherwise.
Because the function body is now part of the caller, the compiler can optimize across what was once a call boundary. For example, if certain arguments are constants at the call site, those constant values may propagate into the inlined function, allowing the compiler to simplify calculations or remove branches inside the function <ref>Inline - Using the GNU Compiler Collection (GCC) https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Inline.html</ref>. In effect, inlining can make two separate functions behave as one larger function, which often enables additional compiler optimizations that would not be possible otherwise.
Bots, Bureaucrats, Interface administrators, smwadministrator, smwcurator, smweditor, Administrators
2,557

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu