-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Emit llvm.{memcpy,memset}.inline when no-builtins attribute is enabled
#137246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
What do you want here? Do you want to avoid calling the |
|
I agree with @dianqk. The purpose of no_builtin / -fno-builtin is to disable recognition of C library calls. It does not affect whether operations can be legalized using libcalls (keep in mind that this is something that extends far beyond memcpy, it also affects FP math libcalls, and all the good stuff provided by libgcc / compiler-builtins). |
Yep, exactly. Today it's kind of impossible to avoid calling |
|
I tried some no-std code with and without
Also seen very few posts around this topic on forums, and it looks like the main thing wanted is to allow using custom Another feature wanted would be to be able to have "typed custom memcopy" to again avoid extra alignment and size checks that are present in generic memcopy in case of copying large structures, for which alignment is guaranteed, but it looks impossible |
I think this is the expected behavior; someone has to provide the implementation eventually. LLVM assumes that The relationship between
It makes sense to me is that allowing users to use their own provided
Yes. It's possible. Just use |
Today we emit
memcpy/memsetllvm intrinsics inrustc_codegen_llvmeven when#![no_builtins]is enabled on the crate. This PR adjusts LLVM'smemcpy/memsetlowering to not do that, since llvm doesn't care to avoid builtins even when the"no-builtins"attribute is enabled on the function.Curiously, I didn't find an inline version for
memmove, lol.The approach that I took with reading the function attrs on the C++ side is a bit janky, but I couldn't find a good way to thread
no_builtins: boolthrough the variousBuilderCx/CodegenCx/Builder/LlvmModule/etc that we have inrustc_codegen_llvm. This seems to be how clang handles lowering inline builtins too -- reading the attrs directly from the function it's building.I also added support for the
"no-builtin-memcpy"/"no-builtin-memmove"attrs even though Rust doesn't emit those today, because it wasn't difficult and it's possible we could add more granularity than#![no_builtins]in the future.r? @nikic perhaps? I have no idea who else reviews LLVM codegen in rustc, so please reassign if you're busy or not the right person for this. I'm also open to other impl strategies.