c - Address of a variable stored in a register -
if somewhere in code, use address of variable (pass other function, example), compiler automatically choose store in memory? (as opposed possibility of storing in register).
otherwise, happens if ask address of variable (stored register)? know can't take address of variables explicitly set register (register int c).
edit:
for example, if
int c = 1; print("address of c: %p", &c); then variable couldn't stored in register, it? compiler automatically set stored in memory? otherwise (if stored in register), address shown in screen?
first, c standard prohibits taking address of variable declared register, bit fields in structs.
for non-register ("auto") variables, short answer yes. simplest strategy of optimizer spill variables addresses taken.
"spill" term literature of register allocation meaning "decide place in memory rather register."
a sophisticated optimizer can alias analysis , still hold value in register, though address has been taken. possible wherever can proven resulting pointer can't possibly used change value.
another relevant optimization live range splitting. allows variable stored in register part of range of instructions it's holding useful value (its "live range") , spilled in other parts. in case spilled parts correspond places pointer might used change variable's value. example:
x = 3; ... lots of computations involving x if t { // spill here, store register holding x memory int *p = &x; ... lots of computations, perhaps using p change x *p = 2; // done spill here, reload register ... more code here not using p change x. } else { ... lots of computations involving x. } an aggressive optimizer of code might allocate stack position x, load register @ top of code, maintaining there except region marked spill. region surrounded store of register memory , matching register load.
Comments
Post a Comment