[llvm] [Inliner] Add support for preserving `nocapture` param attr (PR #113418)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 07:00:01 PST 2024
goldsteinn wrote:
> Can you remind me what the original motivating case was? Something like a nocapture wrapper around inline assembly?
Yes, currently there is no way to apply `nocapture` to the arguments of an assembly call.
For example:
```
#include <stdint.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <linux/futex.h>
static long futex_wait(unsigned const __attribute__((noescape)) * mem,
unsigned val) {
register long r_rax __asm__("rax") = SYS_futex;
register unsigned const * r_rdi __asm__("rdi") = mem;
register long r_rsi __asm__("rsi") = FUTEX_WAIT_PRIVATE;
register unsigned r_rdx __asm__("rdx") = val;
register long r_r10 __asm__("r10") = 0;
__asm__ volatile("syscall"
: "+r"(r_rax)
: "r"(r_rdi), "r"(r_rsi), "r"(r_rdx), "r"(r_r10),
"m"(*((unsigned const(*)[1])r_rdi))
: "r11", "rcx");
return r_rax;
}
long do_futex_wait(unsigned * mem) {
//...
futex_wait(mem, 1);
//...
}
```
When `futex_wait` gets inlined into `do_futex_wait`, the `nocapture` will be lost forever and I don't think there is any way currently to get a `nocapture` on the `mem` argument to the inline-asm callsite.
https://github.com/llvm/llvm-project/pull/113418
More information about the llvm-commits
mailing list