Message ID | a238ab15-5ae3-4f62-f81d-11672e62d667@codesourcery.com |
---|---|
State | New |
Headers | show |
Series | Reduce register usage on AMD GCN | expand |
On 14/11/2019 15:33, Kwok Cheung Yeung wrote: > The kernel attributes are changed to request at least 64 SGPRs and 24 > VGPRs (i.e. the non-kernel maximum, otherwise the callees may not have > enough registers to run in) for non-leaf kernels to take advantage of > the reduced number of registers used in non-kernel functions. > > Okay for trunk? I think you mean "leaf kernels" can use fewer registers. The code looks right. OK (but, again, check the white-space) Andrew
On 15/11/2019 11:32 am, Andrew Stubbs wrote: > On 14/11/2019 15:33, Kwok Cheung Yeung wrote: >> The kernel attributes are changed to request at least 64 SGPRs and 24 >> VGPRs (i.e. the non-kernel maximum, otherwise the callees may not have >> enough registers to run in) for non-leaf kernels to take advantage of >> the reduced number of registers used in non-kernel functions. >> >> Okay for trunk? > > I think you mean "leaf kernels" can use fewer registers. The code looks > right. > No, I definitely mean non-leaf kernels here. Leaf kernels (i.e. kernels that don't call any other functions) can use as many or few registers as they want. Non-leaf kernels must abide by our implied ABI, which states that there are 64 SGPRs and 24 VPGRs available to non-kernel functions. Since the kernel has no way of knowing exactly how many registers are actually used by the functions it calls, it must assume the worst and reserve the whole 64 SGPRs/24 VGPRs, even if the kernel itself makes use of fewer registers. This is still a reduction over the previous 102 SGPRs/64 VGPRs. Kwok
On 15/11/2019 15:51, Kwok Cheung Yeung wrote: > On 15/11/2019 11:32 am, Andrew Stubbs wrote: >> On 14/11/2019 15:33, Kwok Cheung Yeung wrote: >>> The kernel attributes are changed to request at least 64 SGPRs and 24 >>> VGPRs (i.e. the non-kernel maximum, otherwise the callees may not >>> have enough registers to run in) for non-leaf kernels to take >>> advantage of the reduced number of registers used in non-kernel >>> functions. >>> >>> Okay for trunk? >> >> I think you mean "leaf kernels" can use fewer registers. The code >> looks right. >> > > No, I definitely mean non-leaf kernels here. Leaf kernels (i.e. kernels > that don't call any other functions) can use as many or few registers as > they want. Non-leaf kernels must abide by our implied ABI, which states > that there are 64 SGPRs and 24 VPGRs available to non-kernel functions. > Since the kernel has no way of knowing exactly how many registers are > actually used by the functions it calls, it must assume the worst and > reserve the whole 64 SGPRs/24 VGPRs, even if the kernel itself makes use > of fewer registers. This is still a reduction over the previous 102 > SGPRs/64 VGPRs. OK, I failed to parse the English and got to wrong sense of fewer registers. Anyway, the patch is fine. Andrew
diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c index 8a2f7d7..976843b 100644 --- a/gcc/config/gcn/gcn.c +++ b/gcc/config/gcn/gcn.c @@ -75,6 +75,12 @@ int gcn_isa = 3; /* Default to GCN3. */ #define LDS_SIZE 65536 +/* The number of registers usable by normal non-kernel functions. + The SGPR count includes any special extra registers such as VCC. */ + +#define MAX_NORMAL_SGPR_COUNT 64 +#define MAX_NORMAL_VGPR_COUNT 24 + /* }}} */ /* {{{ Initialization and options. */ @@ -2049,10 +2055,12 @@ gcn_conditional_register_usage (void) if (cfun->machine->normal_function) { /* Restrict the set of SGPRs and VGPRs used by non-kernel functions. */ - for (int i = SGPR_REGNO (62); i <= LAST_SGPR_REG; i++) + for (int i = SGPR_REGNO (MAX_NORMAL_SGPR_COUNT - 2); + i <= LAST_SGPR_REG; i++) fixed_regs[i] = 1, call_used_regs[i] = 1; - for (int i = VGPR_REGNO (24); i <= LAST_VGPR_REG; i++) + for (int i = VGPR_REGNO (MAX_NORMAL_VGPR_COUNT); + i <= LAST_VGPR_REG; i++) fixed_regs[i] = 1, call_used_regs[i] = 1;