#pragma execution_frequency

Purpose

Marks program source code that you expect will be either very frequently or very infrequently executed.

When optimization is enabled, the pragma is used as a hint to the optimizer.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-#--pragma--execution_frequency--(--+-very_low--+--)---------><
                                      '-very_high-'      

Parameters

very_low
Marks source code that you expect will be executed very infrequently.
very_high
Marks source code that you expect will be executed very frequently.

Usage

Use this pragma in conjunction with an optimization option; if optimization is not enabled, the pragma has no effect.

The pragma must be placed within block scope, and acts on the closest preceding point of branching.

Examples

In the following example, the pragma is used in an if statement block to mark code that is executed infrequently.
int *array = (int *) malloc(10000);

if (array == NULL) {
    /* Block A */
    #pragma execution_frequency(very_low)
    error();
}
In the next example, the code block Block B is marked as infrequently executed and Block C is likely to be chosen during branching.
if (Foo > 0) {
    #pragma execution_frequency(very_low)
    /* Block B */
    doSomething();
} else {
    /* Block C */
    doAnotherThing();
}
In this example, the pragma is used in a switch statement block to mark code that is executed frequently.
while (counter > 0) {
    #pragma execution_frequency(very_high)    	
    doSomething();
}	/* This loop is very likely to be executed.    */

switch (a) {
    case 1:
        doOneThing();
        break;
    case 2:
        #pragma execution_frequency(very_high)	
        doTwoThings();	
        break;
    default:
        doNothing();
}    /* The second case is frequently chosen.   */


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us