Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Inline expansion
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Benefits == Inline expansion itself is an optimization, since it eliminates overhead from calls, but it is much more important as an [[enabling transformation]]. That is, once the compiler expands a function body in the context of its call site—often with arguments that may be fixed [[Constant (mathematics)|constants]]—it may be able to do a variety of transformations that were not possible before. For example, a [[conditional branch]] may turn out to be always true or always false at this particular call site. This in turn may enable [[dead code elimination]], [[loop-invariant code motion]], or [[induction variable elimination]]. <!-- Need to talk more about how to automatically choose which functions to inline Need to talk more about inlining recursive functions --> In the C example in the prior section, optimizing opportunities abound. The compiler may follow this sequence of steps: * The <code>tmp += 0</code> statements in the lines marked (2) and (3) do nothing. The compiler can remove them. * The condition <code>0 == 0</code> is always true, so the compiler can replace the line marked (2) with the consequent, <code>tmp += 0</code> (which does nothing). * The compiler can rewrite the condition <code>y+1 == 0</code> to <code>y == -1</code>. * The compiler can reduce the expression <code>(y + 1) - 1</code> to <code>y</code>. * The expressions <code>y</code> and <code>y+1</code> cannot both equal zero. This lets the compiler eliminate one test. * In statements such as <code>if (y == 0) return y</code> the value of <code>y</code> is known in the body, and can be inlined. The new function looks like: <syntaxhighlight lang="c"> int func(int y) { if (y == 0) return 0; if (y == -1) return -2; return 2*y - 1; } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)