. global/static: fixed relocatable address or offset with respect to base as global pointer
. stack variable: offset from stack/frame pointer
. allocate stack/global in registers
. registers are not indexable, therefore, arrays cannot be in registers
. assign symbolic registers to scalar variables
. used for graph coloring for global register allocation
Global variables, on the other hand, have static duration ( hence also called static variables): they last, and the values stored in them persist, for as long as the program does. (Of course, the values can in general still be overwritten, so they don't necessarily persist forever.) Therefore they have fixed relocatable address or offset with respect to base as global pointer .
By default, local variables (stack variables) (those declared within a function) have automatic duration : they spring into existence when the function is called, and they (and their values) disappear when the function returns. This is why they are stored in stacks and have offset from stack/frame pointer.
Register allocation is usually done for global variables. Since registers are not indexable, therefore, arrays cannot be in registers as they are indexed data structures.
Graph coloring is a simple technique for allocating register and minimizing register spills that works well in practice. Register spills occur when a register is needed for a computation but all available registers are in use. The contents of one of the registers must be stored in memory to free it up for immediate use. We assign symbolic registers to scalar variables which are used in the graph coloring.
|