Next Previous Contents

## 19. Pragmas

SDCC supports the following #pragma directives. This directives are applicable only at a function level.

- SAVE - this will save all the current options .
- RESTORE - will restore the saved options from the last save. Note that SAVES & RESTOREs cannot be nested. SDCC uses the same buffer to save the options each time a SAVE is called.
- NOGCSE - will stop global subexpression elimination.
- NOINDUCTION - will stop loop induction optimizations .
- NOJTBOUND - will not generate code for boundary value checking , when switch statements are turned into jump-tables.
- NOOVERLAY - the compiler will not overlay the parameters and local variables of a function.
- NOLOOPREVERSE - Will not do loop reversal optimization
- EXCLUDE NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of pair of push/pop instruction in ISR function (using interrupt keyword). The directive should be placed immediately before the ISR function definition and it affects ALL ISR functions following it. To enable the normal register saving for ISR functions use "#pragma EXCLUDE none"
- CALLEE-SAVES function1[,function2[,function3...]] - The compiler by default uses a caller saves convention for register saving across function calls, however this can cause unneccessary register pushing & popping when calling small functions from larger functions. This option can be used to switch the register saving convention for the function names specified. The compiler will not save registers when calling these functions, extra code will be generated at the entry & exit for these functions to save & restore the registers used by these functions, this can SUBSTANTIALLY reduce code & improve run time performance of the generated code. In future the compiler (with interprocedural analysis) will be able to determine the appropriate scheme to use for each function call. If --callee-saves command line option is used, the function names specified in #pragma CALLEE-SAVES is appended to the list of functions specified inthe command line.

The pragma's are intended to be used to turn-off certain optimizations which might cause the compiler to generate extra stack / data space to store compiler generated temporary variables. This usually happens in large functions. Pragma directives should be used as shown in the following example, they are used to control options & optimizations for a given function; pragmas should be placed before and/or after a function, placing pragma's inside a function body could have unpredictable results.

    eg#pragma SAVE   /* save the current settings */
    #pragma NOGCSE
     /* turnoff global subexpression elimination */
    #pragma NOINDUCTION /*
     turn off induction optimizations */
    int foo ()
    {
        ...
        /* large
     code */
        ...
    }
    #pragma RESTORE /* turn the optimizations back
     on */

The compiler will generate a warning message when extra space is allocated. It is strongly recommended that the SAVE and RESTORE pragma's be used when changing options for a function.

Next Previous Contents