https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125266
--- Comment #11 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Richard Sandiford from comment #10) > (In reply to H.J. Lu from comment #9) > > (In reply to Richard Sandiford from comment #8) > > > Yeah, that seems like the right thing to do. But it means that: > > > > > > (a) The reinit_regs calls shouldn't be needed any more. > > > > How do we allow target attribute on a function to enable additional > > registers or disable some registers in a function without calling > > reinit_regs? > I meant that calling reinit_regs isn't necessary for changes in > call_saved_registers_type. I agree that a change is still needed if you're > fixing and unfixing registers. (I should have been clearer, sorry.) > > But a change to the set of available registers is effectively a change to > the current target. So rather than call reinit_regs directly, it would be > better to make ix86_set_current_function switch targets. [More below] > > > > (b) This part of ix86_conditional_register_usage: > > > > > > /* If there are no caller-saved registers, preserve all registers. > > > except fixed_regs and registers used for function return value > > > since aggregate_value_p checks call_used_regs[regno] on return > > > value. */ > > > if (cfun > > > && (cfun->machine->call_saved_registers > > > == TYPE_NO_CALLER_SAVED_REGISTERS)) > > > for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) > > > if (!fixed_regs[i] && !ix86_function_value_regno_p (i)) > > > call_used_regs[i] = 0; > > > > > > should be removed, and should instead be reflected in the > > > function_abi entry. > > > > > > These days, as far as target-independent code is concerned, call_used_regs > > > just exists as a way for the target to communicate the *default* call-used > > > set to init_regs_1, for initialising the default ABI. Other > > > target-independent code does not use call_used_regs & co. Instead it > > > queries the function_abi structures. > > > > > > Thus call_used_regs is not expected to (and should not) change based on > > > the > > > current function's ABI. It should always describe the default ABI. Any > > > variations from the default ABI should be described in the function_abi > > > instead. > > > > If I understand it correctly, call_used_regs only describes registers > > clobbered > > by callee and it shouldn't be used for anything else. > Yeah. Specifically by callees that use the default ABI. The default ABI is vague. What is the default ABI when a file compiled with GPRs only at the command-line? What is the default ABI when a target attribute on a function enables SSE registers which aren't enabled at the command-line? > > If a target attribute > > enables additional registers in a function, shouldn't callee's > > call_used_regs > > in such a function be different, i.e., clobber more registers? Also a > > target > > attribute may reduce number of registers in a function, like GPRs only. How > > does call_used_regs work in these cases? > I suppose it depends on why the register is fixed. Some targets have > special-purpose fixed registers that are call-preserved rather than > call-used. And some targets have fixed registers that are effectively > global (like the FP rounding mode). But if a register isn't being used at > all (like SIMD registers when only GPRs are enabled), then the normal > approach is to treat the register as call-used. I got ICE when I marked x87 registers as call-used while X87 is disabled at the command-line. > The function_abi definitions are a property of the current target, rather > than global. So if ix86_set_current_function treated "GPR only" as a > separate target, that target would also get its own set of specialised > function_abis. Setting up the target would indirectly call > ix86_conditional_register_usage. > > If we did that, the "GPR only" version of the no_caller_saved_registers ABI > would preserve only GPRs, while the "normal" version of the > no_caller_saved_registers ABI would preserve SIMD registers. But like I > say, it would all happen "naturally" through ix86_set_current_target > changing target. When compiling a function, call_used_regs applies to the default ABI. "default" here means that if a callee doesn't have attribute, the callee will use the same call_used_regs as caller.
