#pragma isolated_call

Category

Optimization and tuning

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:

  • Accessing a volatile object
  • Modifying an external object
  • Modifying a static object
  • Modifying a file
  • Accessing a file that is modified by another process or thread
  • Allocating a dynamic object, unless it is released before returning
  • Releasing a dynamic object, unless it was allocated during the same invocation
  • Changing system state, such as rounding mode or exception handling
  • Calling a function that does any of the above

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

Pragma syntax

Read syntax diagramSkip visual syntax diagram#pragmaisolated_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, operator function, conversion function, or qualified name. An identifier must be of type function or a typedef of function. C++ only If the name refers to an overloaded function, all variants of that function are marked as isolated calls.C++ only

Usage

The only side effect that is allowed for a function named in the 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 nonvolatile external objects and return a result that depends on the nonvolatile 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 isolated_call directive can be placed at any point in the source file, before or after calls to the function named in the pragma.

Predefined macros

None.

Examples

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;
}

IPA effects

If you specify this pragma in your source code in the IPA compile step, you cannot override the effects of the pragma on the IPA link step.