On 08/05/2010 06:48 AM, Claudiu Zissulescu wrote: > I want to use a different CALL_USED_REGISTER set per individual > function. The issue here is to inform a caller about the callee > CALL_USED_REGISTERS and save/restore at caller level the possible > altered registers. This should reduce the number of saved/restored > operation in a function. > > Can someone give me some pointers in this direction?
A sketch of the idea: In struct cgraph_local_info, add a HARD_REG_SET with the call-used register set for that function. It is initialized to the ABI. In the various appropriate places, caller-save.c, ira-*.c, reload1.c, sel-sched.c, and replace the bare uses of the target_hard_regs sets with calls to something like HARD_REG_SET get_call_used_reg_set (const_rtx call_insn); HARD_REG_SET get_regs_invalidated_by_call (const_rtx call_insn); which digs into the actual call to find the symbol_ref, and from there to the SYMBOL_REF_DECL, to the cgraph node from whence you can return the saved register set. If any of that fails, you must return the ABI set. At the end of compilation for a function, iterate over the function to see what's really changed. The set of call-clobbered registers that might be used can change right up until at least machine_reorg. Of course one must OR in the sets used by any callees. Store this collected register set back into cgraph_local_info that it may be used during the compilation of the function's callers. Given that cgraph has already performed a topological sort on the set of functions to be emitted, you should in this way be able to collect the call-used register set of most functions before they are used by their callers. The case of cycles is handled by assuming the worst by the initialization to the ABI call-used set. r~ PS: Bonus points for adding an __attribute__((call_used(register-set))) to allow programmers to describe the behaviour of hand-written assembly, or force the function to save more registers in its prologue. The later, of course, means having to adjust the prologue and epilogue code the target(s) you care about. One can support this feature without adjusting the target merely be restricting this to hand-written assembly. Detect this by generating an error if the attribute is used with a function that has a body and is not merely a declaration.