aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
AgeCommit message (Collapse)Author
2025-11-20update deprecated ArrayListUnmanaged usage (#25958)Benjamin Jurk
2025-11-20Merge pull request #25898 from jacobly0/elfv2-progressAndrew Kelley
Elf2: more progress
2025-11-19llvm: fix lowering of packed struct constantsMatthew Lugg
The big-endian logic here was simply incorrect. Luckily, it was also overcomplicated; after calling `Value.writeToPackedMemory`, there is a method on `std.math.big.int.Mutable` which just does the correct endianness load for us.
2025-11-18cbe: fix big-endian unnatural integer bitcastMatthew Lugg
Integers with padding bits on big-endian targets cannot quite be bitcast with a trivial memcpy, because the padding bits (which are zext or sext) are the most-significant, so are at the *lowest* addresses. So to bitcast to something which doesn't have padding bits, we need to offset past the padding. The logic I've added here definitely doesn't handle all possibilities correctly; I think that would actually be quite complicated. However, it handles a common case, and so prevents the Zig compiler itself from being miscompiled on big-endian targets (hence fixing a bootstrapping problem on big-endian).
2025-11-16Dedupe types when printing error messagesProkop Randáček
2025-11-15Merge pull request #25936 from Traxar/masterAndrew Kelley
Add some missing features to `std.Io.Timestamp` and `spirv/CodeGen.zig`
2025-11-15Legalize: implement soft-float legalizationsMatthew Lugg
A new `Legalize.Feature` tag is introduced for each float bit width (16/32/64/80/128). When e.g. `soft_f16` is enabled, all arithmetic and comparison operations on `f16` are converted to calls to the appropriate compiler_rt function using the new AIR tag `.legalize_compiler_rt_call`. This includes casts where the source *or* target type is `f16`, or integer<=>float conversions to or from `f16`. Occasionally, operations are legalized to blocks because there is extra code required; for instance, legalizing `@floatFromInt` where the integer type is larger than 64 bits requires calling an arbitrary-width integer conversion function which accepts a pointer to the integer, so we need to use `alloc` to create such a pointer, and store the integer there (after possibly zero-extending or sign-extending it). No backend currently uses these new legalizations (and as such, no backend currently needs to implement `.legalize_compiler_rt_call`). However, for testing purposes, I tried modifying the self-hosted x86_64 backend to enable all of the soft-float features (and implement the AIR instruction). This modified backend was able to pass all of the behavior tests (except for one `@mod` test where the LLVM backend has a bug resulting in incorrect compiler-rt behavior!), including the tests specific to the self-hosted x86_64 backend. `f16` and `f80` legalizations are likely of particular interest to backend developers, because most architectures do not have instructions to operate on these types. However, enabling *all* of these legalization passes can be useful when developing a new backend to hit the ground running and pass a good amount of tests more easily.
2025-11-15src/codegen/spirv/CodeGen.zig: add missing unary Opstraxar
2025-11-14represent Mac Catalyst as aarch64-maccatalyst-none rather than ↵Alex Rønne Petersen
aarch64-ios-macabi Apple's own headers and tbd files prefer to think of Mac Catalyst as a distinct OS target. Earlier, when DriverKit support was added to LLVM, it was represented a distinct OS. So why Apple decided to only represent Mac Catalyst as an ABI in the target triple is beyond me. But this isn't the first time they've ignored established target triple norms (see: armv7k and aarch64_32) and it probably won't be the last. While doing this, I also audited all Darwin OS prongs throughout the codebase and made sure they cover all the tags.
2025-11-12Merge pull request #25772 from mlugg/kill-dead-codeMatthew Lugg
compiler: rewrite some legalizations, and remove a bunch of dead code
2025-11-12std.Target: remove Abi.cygnusAlex Rønne Petersen
There is approximately zero chance of the Zig team ever spending any effort on supporting Cygwin; the MSVC and MinGW-w64 ABIs are superior in every way that matters, and not least because they lead to binaries that just run natively on Windows without needing a POSIX emulation environment installed.
2025-11-12cbe: work around some miscompilationsMatthew Lugg
The changes to `codegen.c` are blatant hacks, but the problem they work around isn't a regression: it's an existing miscompilation. This branch happened to *expose* that miscompilation in more cases by changing how an incorrect result is *used*.
2025-11-12Air.Legalize: revert to loops for scalarizationsMatthew Lugg
I had tried unrolling the loops to avoid requiring the `vector_store_elem` instruction, but it's arguably a problem to generate O(N) code for an operation on `@Vector(N, T)`. In addition, that lowering emitted a lot of `.aggregate_init` instructions, which is itself a quite difficult operation to codegen. This requires reintroducing runtime vector indexing internally. However, I've put it in a couple of instructions which are intended only for use by `Air.Legalize`, named `legalize_vec_elem_val` (like `array_elem_val`, but for indexing a vector with a runtime-known index) and `legalize_vec_store_elem` (like the old `vector_store_elem` instruction). These are explicitly documented as *not* being emitted by Sema, so need only be implemented by backends if they actually use an `Air.Legalize.Feature` which emits them (otherwise they can be marked as `unreachable`).
2025-11-12x86_64: spill eflags when initializing bool vectorMatthew Lugg
2025-11-12compiler: spring cleaningMatthew Lugg
I started this diff trying to remove a little dead code from the C backend, but ended up finding a bunch of dead code sprinkled all over the place: * `packed` handling in the C backend which was made dead by `Legalize` * Representation of pointers to runtime-known vector indices * Handling for the `vector_store_elem` AIR instruction (now removed) * Old tuple handling from when they used the InternPool repr of structs * Straightforward unused functions * TODOs in the LLVM backend for features which Zig just does not support
2025-11-11Elf2: implement PLTJacob Young
2025-11-11aarch64: cleanup register lockJacob Young
2025-11-10Merge pull request #25886 from alexrp/kvxAlex Rønne Petersen
beginnings of KVX target support (via CBE)
2025-11-10llvm: set sub-arch for spirv 1.6Alex Rønne Petersen
2025-11-10cbe: kvx uses $-prefixed registersAlex Rønne Petersen
2025-11-10std.Target: add Arch tag and info for kvxAlex Rønne Petersen
2025-11-06llvm: add extra clobbers to valgrind requestsDavid Rubin
This seems to work around a very puzzling miscompilation first present in LLVM 21.x. We already unconditionally add these clobbers to inline assembly that came from the source, the valgrind requests should also contain them.
2025-11-06llvm: clobber `rdx` instead of `edx` for x86-64 valgrind requestDavid Rubin
2025-11-04x86_64: implement split vector storesJacob Young
Closes #25809
2025-11-04Fixing SPIR-V header generator magic + Adding Zig compiler version to SPIR-V ↵kbz_8
OpSource (#25435) * fixing Zig generator magic in SPIR-V header; adding zig compiler version to SPIR-V OpSource * Update src/codegen/spirv/Module.zig Co-authored-by: rpkak <67059904+rpkak@users.noreply.github.com> --------- Co-authored-by: rpkak <67059904+rpkak@users.noreply.github.com>
2025-11-01cbe: fix more MIPS register names in inline assemblyBingwu Zhang
2025-10-30Merge pull request #25558 from jacobly0/elfv2-load-objJacob Young
Elf2: start implementing input object loading
2025-10-30aarch64: fix macho external referencesJacob Young
2025-10-30aarch64: implement optional comparisonsJacob Young
2025-10-30std.debug.lockStderrWriter: also return ttyconfMatthew Lugg
`std.Io.tty.Config.detect` may be an expensive check (e.g. involving syscalls), and doing it every time we need to print isn't really necessary; under normal usage, we can compute the value once and cache it for the whole program's execution. Since anyone outputting to stderr may reasonably want this information (in fact they are very likely to), it makes sense to cache it and return it from `lockStderrWriter`. Call sites who do not need it will experience no significant overhead, and can just ignore the TTY config with a `const w, _` destructure.
2025-10-29x86_64: add `lret` encodingJacob Young
Closes #25608
2025-10-29x86_64: continue hacking around unimplemented linker logicJacob Young
Closes #25666
2025-10-29x86_64: fix encoding for out with an immediate portJacob Young
Closes #25547
2025-10-29Elf2: start implementing dynamic linkingJacob Young
2025-10-29Elf2: load relocations from input objectsJacob Young
2025-10-29Merge pull request #25592 from ziglang/init-std.IoAndrew Kelley
std: Introduce `Io` Interface
2025-10-29remove all IBM AIX and z/OS supportAlex Rønne Petersen
As with Solaris (dba1bf935390ddb0184a4dc72245454de6c06fd2), we have no way to actually audit contributions for these OSs. IBM also makes it even harder than Oracle to actually obtain these OSs. closes #23695 closes #23694 closes #3655 closes #23693
2025-10-29wasm linking: handle unreachable call_indirectAndrew Kelley
The compiler crashed when we tried to call a function pointer for which the type signature does not match any function body or function import in the entire wasm executable, because there is no way to create a reference to a function without it being in the function table or import table. Solution is to make this instruction lower to unreachable.
2025-10-29compiler: update for introduction of std.IoAndrew Kelley
only thing remaining is using libc dns resolution when linking libc
2025-10-28spirv: fix airWorkGroupSize to use workgroup_size builtinCooksey99
2025-10-28Merge pull request #25691 from GasInfinity-Forks/x86_16-gccAlex Rønne Petersen
feat: init x86_16 arch via CBE
2025-10-27remove all Oracle Solaris supportAlex Rønne Petersen
There is no straightforward way for the Zig team to access the Solaris system headers; to do this, one has to create an Oracle account, accept their EULA to download the installer ISO, and finally install it on a machine or VM. We do not have to jump through hoops like this for any other OS that we support, and no one on the team has expressed willingness to do it. As a result, we cannot audit any Solaris contributions to std.c or other similarly sensitive parts of the standard library. The best we would be able to do is assume that Solaris and illumos are 100% compatible with no way to verify that assumption. But at that point, the solaris and illumos OS tags would be functionally identical anyway. For Solaris especially, any contributions that involve APIs introduced after the OS was made closed-source would also be inherently more risky than equivalent contributions for other proprietary OSs due to the case of Google LLC v. Oracle America, Inc., wherein Oracle clearly demonstrated its willingness to pursue legal action against entities that merely copy API declarations. Finally, Oracle laid off most of the Solaris team in 2017; the OS has been in maintenance mode since, presumably to be retired completely sometime in the 2030s. For these reasons, this commit removes all Oracle Solaris support. Anyone who still wishes to use Zig on Solaris can try their luck by simply using illumos instead of solaris in target triples - chances are it'll work. But there will be no effort from the Zig team to support this use case; we recommend that people move to illumos instead.
2025-10-27feat: init x86_16 arch via CBEGasInfinity
2025-10-25llvm: remove some workarounds in loadTruncate()Alex Rønne Petersen
No longer needed with LLVM 21.
2025-10-23std.builtin: add CallingConvention.sh_interruptAlex Rønne Petersen
Only supported in CBE.
2025-10-23std.builtin: add CallingConvention.microblaze_interruptAlex Rønne Petersen
Only supported in CBE.
2025-10-23std.builtin: add CallingConvention.msp430_interruptAlex Rønne Petersen
Supported by LLVM and CBE.
2025-10-23std.builtin: add CallingConvention.x86_64_x32Alex Rønne Petersen
This was forgotten during the refactoring of std.builtin.CallingConvention. It mirrors mips64_n32 for MIPS.
2025-10-23std.Target: add tags and info for alpha, hppa, microblaze, shAlex Rønne Petersen
2025-10-23std.Target: add arceb and xtensaeb Cpu.Arch tagsAlex Rønne Petersen