HP C Programmer's Guide (92434-90009)

102 Chapter4
Optimizing HP C Programs
Optimizer Pragmas
For example, to specify inlining of the two subprograms checkstat and getinput, use:
#pragma INLINE checkstat, getinput
To specify that an infrequently called routine should not be inlined when compiling at
optimization level 3 or 4, use:
#pragma NOINLINE opendb
See the related +O[no]inline optimization option.
Alias Pragmas
The compiler gathers information about each function (such as information about function
calls, variables, parameters, and return values) and passes this information to the
optimizer. The NO_SIDE_EFFECTS and ALLOCS_NEW_MEMORY pragma tell the optimizer to
make assumptions it can not normally make, resulting in improved compile-time and
run-time speed. They change the default information the compiler collects.
If used, the NO_SIDE_EFFECTS and ALLOCS_NEW_MEMORY pragmas should appear before the
first function defined in a file and are in effect for the entire file. When used appropriately,
these optional pragmas provide better optimization.
NO_SIDE_EFFECTS Pragma
By default, the optimizer assumes that all functions
might
modify global variables. To
some degree, this assumption limits the extent of optimizations it can perform on global
variables. The NO_SIDE_EFFECTS directive provides a way to override this assumption. If
you know for certain that some functions do
not
modify global variables, you can gain
further optimization of code containing calls to these functions by specifying the function
names in this directive.
NO_SIDE_EFFECTS has the following form:
pragma NO_SIDE_EFFECTS
functionname(1)
, ...,
functionname(n)
All functions in
functionname
are the names of functions that do not modify the values of
global variables. Global variable references can be optimized to a greater extent in the
presence of calls to the listed functions. Note that you need the NO_SIDE_EFFECTS directive
in the files where the calls are made, not where the function is defined. This directive takes
effect from the line it first occurs on to the end of the file.
ALLOCS_NEW_MEMORY pragma
The ALLOCS_NEW_MEMORY pragma states that the function
functionname
returns a pointer
to new memory that it either allocates or a routine that it calls allocates.
ALLOCS_NEW_MEMORY has the following form:
pragma ALLOCS_NEW_MEMORY
functionname(1)
, ...,
functionname(n)
The new memory must be memory that was either newly allocated or was previously freed
and is now reallocated. For example, the standard routines malloc() and calloc() satisfy
this requirement.
Large applications might have routines that are layered above malloc() and calloc().
These interface routines make the calls to malloc() and calloc(), initialize the memory,