29.10.2014 Views

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Compiler</strong> Coding Practices<br />

5.20 <strong>Compiler</strong> decisions on function inlining<br />

When function inlining is enabled, <strong>the</strong> compiler uses a complex decision tree to decide if a<br />

function is to be inlined.<br />

The following simplified algorithm is used:<br />

1. If <strong>the</strong> function is qualified with __<strong>for</strong>ceinline, <strong>the</strong> function is inlined if it is possible to do<br />

so.<br />

2. If <strong>the</strong> function is qualified with __inline and <strong>the</strong> option --<strong>for</strong>ceinline is selected, <strong>the</strong><br />

function is inlined if it is possible to do so.<br />

If <strong>the</strong> function is qualified with __inline and <strong>the</strong> option --<strong>for</strong>ceinline is not selected, <strong>the</strong><br />

function is inlined if it is practical to do so.<br />

3. If <strong>the</strong> optimization level is -O2 or higher, or --autoinline is specified, <strong>the</strong> compiler<br />

automatically inlines functions if it is practical to do so, even if you do not explicitly give<br />

a hint that function inlining is wanted.<br />

When deciding if it is practical to inline a function, <strong>the</strong> compiler takes into account several o<strong>the</strong>r<br />

criteria, such as:<br />

• <strong>the</strong> size of <strong>the</strong> function, and how many times it is called<br />

• <strong>the</strong> current optimization level<br />

• whe<strong>the</strong>r it is optimizing <strong>for</strong> speed (-Otime) or size (-Ospace)<br />

• whe<strong>the</strong>r <strong>the</strong> function has external or static linkage<br />

• how many parameters <strong>the</strong> function has<br />

• whe<strong>the</strong>r <strong>the</strong> return value of <strong>the</strong> function is used.<br />

Ultimately, <strong>the</strong> compiler can decide not to inline a function, even if <strong>the</strong> function is qualified with<br />

__<strong>for</strong>ceinline. As a general rule:<br />

• smaller functions stand a better chance of being inlined<br />

• compiling with -Otime increases <strong>the</strong> likelihood that a function is inlined<br />

• large functions are not normally inlined because this can adversely affect code density and<br />

per<strong>for</strong>mance.<br />

A recursive function is inlined into itself only once, even if __<strong>for</strong>ceinline is used.<br />

5.20.1 See also<br />

Concepts<br />

• Inline functions on page 5-29<br />

• Automatic function inlining and static functions on page 5-32<br />

• Automatic function inlining and multifile compilation on page 5-34<br />

• Restriction on overriding compiler decisions about function inlining on page 5-35.<br />

Reference<br />

<strong>Compiler</strong> Reference:<br />

• --autoinline, --no_autoinline on page 3-14<br />

• __<strong>for</strong>ceinline on page 5-5<br />

• --<strong>for</strong>ceinline on page 3-40<br />

• __inline on page 5-7<br />

• --inline, --no_inline on page 3-53<br />

<strong>ARM</strong> DUI 0375C Copyright © 2007-2008, 2011 <strong>ARM</strong>. All rights reserved. 5-30<br />

ID061811<br />

Non-Confidential

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!