Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 208
 2012 Microchip Technology Inc.
5.13
OPTIMIZATIONS
The optimizations in MPLAB XC8 compiler can broadly be broadly grouped into C-level 
optimizations performed on the source code before conversion into assembly; and 
assembly-level optimizations performed on the assembly code generated by the com-
piler.
The C-level optimizations are performed early during the code generation phase and 
so have flow-on benefits: performing one optimizations may mean that another can 
then be applied.
As these optimizations are applied before the debug information has been produced, 
there is typically little impact on source-level debugging of programs.
Some of these optimizations are integral to the code generation process and so cannot 
be disabled via an option. Suggestions as to how specific optimizations can be 
defeated are given in the sections below.
In Standard mode, and particularly Free mode, some of these optimizations are dis-
abled. Even if they are enabled, they may only be applied if very specific conditions are 
met. As a result, you might find that some lines of code are optimized, but others are 
not.
The main C-level optimizations which simplify or change the C expressions are listed 
below.
Unused variables in a program are removed. Variables removed will not have mem-
ory reserved for them, will not appear in any list or map file, and will not be 
present in debug information, and so will not be observable in the debugger. 
A warning is produced if an unused variable is encountered.
Objects qualified volatile will never be removed, see 
Section 5.4.7.2 “Volatile Type Qualifier”. Taking the address of a variable 
or referencing its assembly-domain symbol in hand-written assembly code 
also constitutes use of the variable.
Redundant assignments to variables not subsequently used are removed, unless 
the variable is volatile. The assignment statement is completely re-
moved, as if it was never present in the original source code. No code will be 
produced for it, and you will not be able to set a breakpoint on that line in the 
debugger.
Unused functions in a program are removed. A function is considered unused if it is 
not called, directly or indirectly, nor has had its address taken. The entire 
function is removed, as if it was never present in the original source code. No 
code will be produced for it and you will not be able to set a breakpoint on 
any line in the function in the debugger.
Referencing a function’s assembly-domain symbol in a separate hand-writ-
ten assembly module will prevent it being removed. The assembly code 
need only use the symbol in the GLOBAL directive.
Unused return expressions in a function are removed. The return value is consid-
ered unused if the result of all calls to that function discard the return value. 
The code associated with calculation of the return value will be removed, and 
the function will be encoded as if its return type was void.
Propagation of constants is performed where the numerical contents of a variable 
can be determined. Variables which are not volatile and whose value can be 
exactly determined are replaced with the numerical value. Uninitialized 
global variables are assumed to contain zero prior to any assignment to 
them.