The global register allocation option (/Oe) instructs the compiler to analyze your program and allocate CPU registers as efficiently as possible. Without the global register allocation option, the compiler uses the CPU's registers for several purposes:
Holding temporary copies of variables
Holding variables declared with the register keyword
Passing parameters to functions declared with the __fastcall keyword (or functions in programs compiled with the /Gr command-line option)
Summary: Variables in registers are sometimes placed back in memory.
When you enable global register allocation, the compiler ignores the register keyword and allocates register storage to variables (and possibly to common subexpressions). The compiler allocates register storage to variables or subexpressions according to frequency of use. Because of the limited number of physical registers, variables held in registers are sometimes placed back in memory to free the register for another use.
Here is a C program example that demonstrates how the compiler might rewrite your code to accomplish this:
/* Original program */
func()
{
int i, j;
char *pc;
for( i = 0; i < 1000; ++i )
{
j = i / 3;
*pc++ = (char)i;
}
for( j = 0, —pc; j < 1000;
++j, —pc )
*pc—;
}
/* Example of how the compiler might optimize the
* code to move i and j in and out of registers */
func()
{
int i, j;
char *pc;
{
register int i; /* i is in a register for this block. */
for( i = 0; i < 1000; ++i )
{
j = i / 3;
*pc++ = (char)i;
}
}
{
register int j; /* j is in a register for this block. */
for( j = 0, —pc; j < 1000;
++j, —pc )
*pc—;
}
}
In the preceding example, there are blocks (enclosed in curly braces) whose only purpose is to delimit the span of code across which variables should remain in registers.
Note:
You can enable or disable global register allocation on a function-by-function basis using the optimize pragma with the e option.
Calling the setjmp or longjmp functions when global register optimization is in effect can cause the compiler to generate incorrect code. Use the optimize pragma with the e option to disable this optimization in functions that call setjmp and longjmp.