-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
llvm
: Use inline variants of memcpy
/memset
intrinsics when using -fno-builtin
#22903
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
cc @dweiller |
This is missing an |
Is the length being constant actually a requirement of these intrinsics? |
Yes, you will get a very unhelpful llvm error if it's not. |
Looks like they may have removed it in llvm 19, in which case you would have to fix the definition of the intrinsics in |
Even switch (builder.constant_items.items(.tag)[len.toConst().?.unwrap().constant]) {
.positive_integer, .negative_integer => {},
else => unreachable,
} which could probably be a function on |
Ah, I see. Regarding backwards compatibility, in a way, we're already tied to the LLVM version we currently target anyway due to e.g. our choice of I guess we need to figure out how much we actually care about bitcode backwards compatibility at this stage, and if we do, maybe add a flag for the user to specify the target LLVM version. |
Keep in mind that |
If the concern is mainly about third-party users of |
Maybe, but the proper assert in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally not concerned about supporting old bitcode versions (yet?). The Roc folks want to share maintenance of Builder however, so might be nice to coordinate with them about it.
There are lots of strategies for deciding how to maintain this logic, I'm open to many of them.
I'd be interested in, for starters, changing nothing about this repository, but additionally copying this logic to a separately maintained package for use by Roc and other third party projects. I don't think zig should depend on network access in order to build, since it is "dependency zero".
would moving it to |
Quoting @bhansconnect from the Roc Zulip:
|
02a64e9
to
cbd7d94
Compare
…-builtin. This is a correctness issue: When -fno-builtin is used, we must assume that we could be compiling the memcpy/memset implementations, so generating calls to them is problematic.
cbd7d94
to
21eb757
Compare
Note that I was also thinking about the use case of no longer linking the compiler with libLLVM and supporting using the system llvm toolchain. This would require continuing to support the oldest version of llvm still in use by common distros. If the plan is to only support some newer llvm package provided by us and compiled like zig bootstrap, maybe this isn't a concern. |
I think that is quite a sensible option. It can be defined to be an unstable API that suits whatever needs the compiler has, and if another project wants API stability beyond locking the Zig version, or additional changes, they can maintain a fork. For Roc's purposes, I predict they can start by directly depending on the std lib API, however, inevitably they will want to make some enhancement or fix some bug, and then will be forced to copy the implementation into their codebase. However, if they are diligent in upstreaming those enhancements and fixes, then eventually could delete the fork when a new zig version is released. For system toolchain compatibility, the only thing that is needed is for Zig releases to continue to keep up with LLVM releases. A given system with old llvm should have old (matching) zig. I think the use case of new, upstream-provided zig mixed with old, system-provided clang is not particularly valuable. The purpose of system toolchains is primarily to build system packages. Upstream-provided zig can and should be self-sufficient. |
I think Jacob's point about system toolchains is not too far-fetched. Keep in mind that e.g. Debian/Ubuntu carry like 5-6 different LLVM versions in their repositories at any given time, and |
What's your system Zig in this case? Is it not the one that links LLVM 18? Edit: ubuntu 24.04 doesn't have a zig package, so I don't know what you mean by "system zig". |
I indeed don't have a system Zig. To clarify, Ubuntu 24.04 has packages for LLVM 14 through 19, but the default tools are still LLVM 18. That means that if we were in a hypothetical world where Ubuntu 24.04 had a system Zig that didn't depend on libLLVM, it would more than likely be a version that's expecting to use LLVM 19, but e.g. |
I don't buy it. If they have multiple versions of LLVM then they can have multiple versions of zig, with a one-to-one correspondence. Or at least the version of system zig will have a corresponding LLVM on the system. |
This is a correctness issue: When
-fno-builtin
is used, we must assume that we could be compiling thememcpy
/memset
implementations, so generating calls to them is problematic.