-qisolated_call

Category

Optimization and tuning

Pragma equivalent

#pragma options isolated_call, #pragma isolated_call

Purpose

Specifies functions in the source file that have no side effects other than those implied by their parameters.

Essentially, any change in the state of the runtime environment is considered a side effect, including:

Marking a function as isolated indicates to the optimizer that external and static variables cannot be changed by the called function and that pessimistic references to storage can be deleted from the calling function where appropriate. Instructions can be reordered with more freedom, resulting in fewer pipeline delays and faster execution in the processor. Multiple calls to the same function with identical parameters can be combined, calls can be deleted if their results are not needed, and the order of calls can be changed.

Syntax

Read syntax diagramSkip visual syntax diagram
Option syntax

                          .-:--------.   
                          V          |   
>>- -q--isolated_call--=----function-+-------------------------><

Read syntax diagramSkip visual syntax diagram
Pragma syntax

>>-#--pragma--isolated_call--(--function--)--------------------><

Defaults

Not applicable.

Parameters

function
The name of a function that does not have side effects or does not rely on functions or processes that have side effects. function is a primary expression that can be an identifier. An identifier must be of type function or a typedef of function.

Usage

The only side effect that is allowed for a function named in the option or pragma is modifying the storage pointed to by any pointer arguments passed to the function, that is, calls by reference. The function is also permitted to examine non-volatile external objects and return a result that depends on the non-volatile state of the runtime environment. Do not specify a function that causes any other side effects; that calls itself; or that relies on local static storage. If a function is incorrectly identified as having no side effects, the program behavior might be unexpected or produce incorrect results.

The #pragma options isolated_call directive must be placed at the top of a source file, before any statements. The #pragma isolated_call directive can be placed at any point in the source file, before or after calls to the function named in the pragma.

The -qignprag compiler option causes aliasing pragmas to be ignored; you can use -qignprag to debug applications containing the #pragma isolated_call directive.

Predefined macros

None.

Examples

To compile myprogram.c, specifying that the functions myfunction(int) and classfunction(double) do not have side effects, enter:
xlc myprogram.c -qisolated_call=myfunction:classfunction
The following example shows you when to use the #pragma isolated_call directive (on the addmult function). It also shows you when not to use it (on the same and check functions):
#include <stdio.h>
#include <math.h>

int addmult(int op1, int op2);
#pragma isolated_call(addmult)

/* This function is a good candidate to be flagged as isolated as its */
/* result is constant with constant input and it has no side effects. */
int addmult(int op1, int op2) {
  int rslt;

  rslt = op1*op2 + op2;
  return rslt;
}

/* The function 'same' should not be flagged as isolated as its state */
/* (the static variable delta) can change when it is called. */
int same(double op1, double op2) {
  static double delta = 1.0;
  double temp;

  temp = (op1-op2)/op1;
  if (fabs(temp) < delta)
    return 1;
  else {
    delta = delta / 2;
    return 0;
  }
}

/* The function 'check' should not be flagged as isolated as it has a */
/* side effect of possibly emitting output. */
int check(int op1, int op2) {
  if (op1 < op2)
    return -1;
  if (op1 > op2)
    return 1;
  printf("Operands are the same.\n");
  return 0;
}

Related information