[clang] [llvm] [BPF] introduce `__attribute__((bpf_fastcall))` (PR #101228)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 5 12:50:46 PDT 2024


eddyz87 wrote:

@AaronBallman,

> > ```c
> >     void (*ptr1)(void) __bpf_fastcall;
> >     void (*ptr2)(void);
> >     void foo(void) {
> >       ptr2 = ptr1; // is this an error?
> >     }
> > ```
> ...
> Doesn't that kind of defeat the purpose of the calling convention? (A function designator decays into a function pointer basically any time you mention it.)
>
> > This commit introduces attribute bpf_fastcall to declare BPF functions that do not clobber some of the caller saved registers (R0-R5).
>
> If the attribute can be dropped, then the caller side has to assume the caller-saved registers are still going to be clobbered even in the presence of the attribute, so it always has to save and restore those registers, doesn't it?

If attribute is dropped, then yes. E.g. if function is called through `ptr2` from the example above, the register allocator would assume that all caller saved registers are clobbered. However, the generated code is still correct, nothing will break or behave unexpectedly. Worst case, some performance would be left on a table. That's why I'm sort-of inclined to say that this is not an error.


https://github.com/llvm/llvm-project/pull/101228


More information about the cfe-commits mailing list