[DTrace-devel] [PATCH 03/10] Exclude %r0 from automatic register allocation

Kris Van Hees kris.van.hees at oracle.com
Fri Mar 18 23:43:05 UTC 2022


On Fri, Mar 18, 2022 at 07:30:03PM -0400, Eugene Loh via DTrace-devel wrote:
> On 3/18/22 7:11 PM, Kris Van Hees wrote:
> 
> > On Fri, Mar 18, 2022 at 05:06:10PM -0400, Eugene Loh via DTrace-devel wrote:
> > > On 3/18/22 3:04 PM, Kris Van Hees via DTrace-devel wrote:
> > > > be allocated when dt_regset_alloc() is called.
> > > So this patch should also:
> > > *) in dt_cg.c, remove those dozens of dt_regset_xalloc() calls along with
> > > their corresponding frees
> > > *) in dt_regset.h, remove dt_regset_xalloc()
> > > *) in dt_regset.c, make dt_regset_xalloc() static
> > No, no, and no :)  We still want to be able to alloc and free %r0 explicitly.
> Why?
> 
> Or e.g. why do we use BPF_REG_0 explicitly in dt_cg_ternary_op() without
> xalloc'ing it?

Because we should have and we didn't.  We probably can stop doing explici
allocs for it, if we are careful to only use %r0 as a scratch register in
cases where we do not call any other cg functions while we are using it.
That is the main reason I still use xalloc/free for %r0 in code that might
get called in that situation (or that might make calls).  Careful audit
probably allows us to reduce most of those, but I don't mind being rather
safe than sorry.

But in a code sequence where nothing else gets called, i.e. really using it
as a scratch register (or a temp reg), not doing the alloc is usually safe.
Unless we might have been called by some other cg function that decides to
allocate it for its own use, across calling our function.

> > But perhaps I should add an explicit check to ensure that we do not alloc %r0
> > when it is already in use.  I will do that.
> > 
> > > > This patch also offers a minor improvement in the regset debugging
> > > > output, reporting in-use registers by number rather than with a 'x'
> > > > in the register list.
> > > Well, this change unnecessarily throws away active/spill info.
> > Ah bah, that is true.  I'll fix that (possibly by printing two lists).
> Or make it wider with an annotations next to spilled regs?  E.g.
>       *2
> or something.  Up to you I guess.  I suspect there are not many users of
> this functionality.

No, probably not.  Mostly me, I think :)  And with the spill/restore
annotations this regset dump becomes less needed as well.



More information about the DTrace-devel mailing list