worley@compass.com (Dale Worley) (02/23/90)
Mohd Hanafiah b. Abdullah writes: > How does one perform register allocation on scalar variables that may > be pointed to by others? The usual strategy is to never leave the value of the variable in a register, since it may be fetched or modified at any time via the pointer. On some hardware, registers have addresses and this conservative strategy may not be needed. A more interesting approach would be to analyze which parts of the program might reference the variable through a pointer and which can not -- then you know in which parts of the program you have to leave the value in its "official" location and in which parts you can leave the variable in a register. This requires serious global data-flow analysis, which, although possible, is rarely implemented. Dale Worley Compass, Inc. worley@compass.com -- Send compilers articles to compilers@esegue.segue.boston.ma.us {spdcc | ima | lotus}!esegue. Meta-mail to compilers-request@esegue. Please send responses to the author of the message, not the poster.
jac@paul.rutgers.edu (Jonathan A. Chandross) (02/23/90)
Mohd Hanafiah b. Abdullah writes: > How does one perform register allocation on scalar variables that may > be pointed to by others? worley@compass.com (Dale Worley) > The usual strategy is to never leave the value of the variable in a register, > since it may be fetched or modified at any time via the pointer. On some > hardware, registers have addresses and this conservative strategy may not be > needed. I suspect you will still have to perform the flow analysis even if the register has a memory address because a register might be be spilled at any given time. This would mean that the pointer would modify the value in the register, not in the memory location that register was spilled to. Certainly would make for interesting bugs. Jonathan A. Chandross Internet: jac@paul.rutgers.edu UUCP: rutgers!paul.rutgers.edu!jac [I suspect he was assuming that the variable is in the register for the duration of the routine, but your point is well taken. Particularly if you pass a pointer to the variable to another procedure, the variable is liable not to be there by the time the pointer is deferenced. -John] -- Send compilers articles to compilers@esegue.segue.boston.ma.us {spdcc | ima | lotus}!esegue. Meta-mail to compilers-request@esegue. Please send responses to the author of the message, not the poster.