aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
AgeCommit message (Collapse)Author
2024-06-13riscv: float argsDavid Rubin
2024-06-10spirv: improve shuffle codegenRobin Voetter
2024-06-10spirv: new vectorization helperRobin Voetter
The old vectorization helper (WipElementWise) was clunky and a bit annoying to use, and it wasn't really flexible enough. This introduces a new vectorization helper, which uses Temporary and Operation types to deduce a Vectorization to perform the operation in a reasonably efficient manner. It removes the outer loop required by WipElementWise so that implementations of AIR instructions are cleaner. This helps with sanity when we start to introduce support for composite integers. airShift, convertToDirect, convertToIndirect, and normalize are initially implemented using this new method.
2024-06-10spirv: remove OpCompositeConstruct workaroundsRobin Voetter
Now that we use POCL to test, we no longer need this ✨
2024-06-10spirv: change direct vector child repr to directRobin Voetter
Previously the child type of a vector was always in indirect representation. Concretely, this meant that vectors of bools are represented by vectors of u8. This was undesirable because it introduced a difference between vectorizable operations with a scalar bool and a vector of bool. This commit changes the representation to be the same for vectors and scalars everywhere. Some issues arised with constructing vectors: it seems the previous temporary- and-pointer approach does not work properly with vectors of bool. To work around this, simply use OpCompositeConstruct. This is the proper instruction for this, but it was previously not used because of a now-solved limitation in the SPIRV-LLVM-Translator. It was not yet applied to Zig because the Intel OpenCL CPU runtime does not have a recent enough version of the translator yet, but to solve that we just switch to testing with POCL instead.
2024-06-05Merge pull request #20120 from vahur/move-consts-to-rdataAndrew Kelley
mark anondecls as constants in llvm ir
2024-06-05LLVM backend: loongarch64 supportAndrew Kelley
2024-06-02pass `-fno-builtin` when testing `lib/c.zig`, `lib/compiler_rt.zig`Veikka Tuominen
2024-06-01llvm: disable constant anons on DarwinVeikka Tuominen
2024-05-30mark anondecls as constants in llvm irVahur Sinijärv
2024-05-22Revert "implement `@expect` builtin (#19658)"Andrew Kelley
This reverts commit a7de02e05216db9a04e438703ddf1b6b12f3fbef. This did not implement the accepted proposal, and I did not sign off on the changes. I would like a chance to review this, please.
2024-05-22implement `@expect` builtin (#19658)David Rubin
* implement `@expect` * add docs * add a second arg for expected bool * fix typo * move `expect` to use BinOp * update to newer langref format
2024-05-22llvm: fix `@wasmMemory{Size,Grow}` for wasm64Veikka Tuominen
Closes #19942
2024-05-21llvm: fix lowering of packed structs with optional pointersVeikka Tuominen
Closes #20022
2024-05-21llvm: lower ptr to int constants with correct address spacesVeikka Tuominen
Closes #19915
2024-05-20Target: add OpenHarmonyOS ABIVeikka Tuominen
Closes #20009
2024-05-11riscv: implement slicesDavid Rubin
2024-05-09llvm: always include debug information for global variablesPyry Kovanen
2024-05-09codegen/llvm: handle missing Apple targetsJakub Konka
2024-05-09handle visionos target OS tag in the compilerJakub Konka
* rename .xros to .visionos as agreed in the tracking issue * add support for VisionOS platform in the MachO linker
2024-05-08LLVM: zeroext/signext does happen on macosAndrew Kelley
Fixes a regression introduced in 3ce7fee9dd8bbb6f56e47758a9a8ada028400c71.
2024-05-08LLVM: fix x86 and x86_64 datalayout string calculationAndrew Kelley
now it matches clang again
2024-05-08add a debug subcommand for printing LLVM integer type alignmentAndrew Kelley
Useful when debugging why upgrading from LLVM 17 to 18 caused C ABI regressions. Turns out LLVM 18 does the following insane thing: ```diff -[nix-shell:~/dev/zig/build-llvm17]$ stage4/bin/zig llvm-ints i386-linux-musl +[nix-shell:~/src/zig/build-llvm18]$ stage4/bin/zig llvm-ints i386-linux-musl LLVMABIAlignmentOfType(i1) == 1 LLVMABIAlignmentOfType(i8) == 1 LLVMABIAlignmentOfType(i16) == 2 LLVMABIAlignmentOfType(i32) == 4 LLVMABIAlignmentOfType(i64) == 4 -LLVMABIAlignmentOfType(i128) == 4 -LLVMABIAlignmentOfType(i256) == 4 +LLVMABIAlignmentOfType(i128) == 16 +LLVMABIAlignmentOfType(i256) == 16 ```
2024-05-08LLVM backend: no more signext on aarch64Andrew Kelley
Clang doesn't do it, so Zig must not do it in order to match the C ABI.
2024-05-08x86_64 sysv C ABI: fix f128 param and return typesAndrew Kelley
Clang 17 passed struct{f128} parameters using rdi and rax, while Clang 18 matches GCC 13.2 behavior, passing them using xmm0. This commit makes Zig's LLVM backend match Clang 18 and GCC 13.2. The commit deletes a hack in x86_64/abi.zig which miscategorized f128 as "memory" which obviously disagreed with the spec.
2024-05-08std.Target.maxIntAlignment: move to compiler implementationAndrew Kelley
This should not be a public API, and the x86 backend does not support the value 16.
2024-05-08add detect-cpu subcommand for debugging CPU featuresAndrew Kelley
This brings back `detectNativeCpuWithLLVM` so that we can troubleshoot during LLVM upgrades. closes #19793
2024-05-08LLVM 18 update: avoid passing vectors sometimesAndrew Kelley
LLVM now refuses to lower arguments and return values on x86 targets when the total vector bit size is >= 512. This code detects such a situation and uses byref instead of byval.
2024-05-08LLVM 18 std lib updates and fixesAndrew Kelley
* some manual fixes to generated CPU features code. In the future it would be nice to make the script do those automatically. * add to various target OS switches. Some of the values I was unsure of and added TODO panics, for example in the case of spirv CPU arch.
2024-05-08update for LLVM 18 new target dataAndrew Kelley
New OSs: * XROS * Serenity * Vulkan Removed OSs: * Ananas * CloudABI * Minix * Contiki New CPUs: * spirv The removed stuff is removed from LLVM but not Zig.
2024-05-04InternPool: eliminate `var_args_param_type`mlugg
This was a "fake" type used to handle C varargs parameters, much like generic poison. In fact, it is treated identically to generic poison in all cases other than one (the final coercion of a call argument), which is trivially special-cased. Thus, it makes sense to remove this special tag and instead use `generic_poison_type` in its place. This fixes several bugs in Sema related to missing handling of this tag. Resolves: #19781
2024-05-02LLVM: Fix panic when using tagged union backed by enum with negative valuesAnton Lilja
2024-04-30cbe: fix ub with integer `@abs`Jacob Young
2024-04-30C backend: avoid memcpy when len=0Andrew Kelley
As of Clang 18, calling memcpy() with a misaligned pointer trips UBSAN, even if the length is zero. This unfortunately includes any call to `@memcpy` when source or destination are undefined and the length is zero. This patch makes the C backend avoid calling memcpy when the length is zero, thereby avoiding undefined behavior. A zig1.wasm update will be needed in the llvm18 branch to activate this code.
2024-04-28Sema+llvm: properly implement `Interrupt` callconvJulian
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2024-04-25LLVM: Remove deprecated or soon to be deprecated constant expressionsantlilja
2024-04-22ComptimeStringMap: return a regular struct and optimizeTravis Staloch
this patch renames ComptimeStringMap to StaticStringMap, makes it accept only a single type parameter, and return a known struct type instead of an anonymous struct. initial motivation for these changes was to reduce the 'very long type names' issue described here https://github.com/ziglang/zig/pull/19682. this breaks the previous API. users will now need to write: `const map = std.StaticStringMap(T).initComptime(kvs_list);` * move `kvs_list` param from type param to an `initComptime()` param * new public methods * `keys()`, `values()` helpers * `init(allocator)`, `deinit(allocator)` for runtime data * `getLongestPrefix(str)`, `getLongestPrefixIndex(str)` - i'm not sure these belong but have left in for now incase they are deemed useful * performance notes: * i posted some benchmarking results here: https://github.com/travisstaloch/comptime-string-map-revised/issues/1 * i noticed a speedup reducing the size of the struct from 48 to 32 bytes and thus use u32s instead of usize for all length fields * i noticed speedup storing KVs as a struct of arrays * latest benchmark shows these wall_time improvements for debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full output in link above.
2024-04-22x86_64: fix C abi for unionsJacob Young
Closes #19721
2024-04-19llvm: fix debug info when running testsJacob Young
2024-04-17compiler: rework comptime pointer representation and accessmlugg
We've got a big one here! This commit reworks how we represent pointers in the InternPool, and rewrites the logic for loading and storing from them at comptime. Firstly, the pointer representation. Previously, pointers were represented in a highly structured manner: pointers to fields, array elements, etc, were explicitly represented. This works well for simple cases, but is quite difficult to handle in the cases of unusual reinterpretations, pointer casts, offsets, etc. Therefore, pointers are now represented in a more "flat" manner. For types without well-defined layouts -- such as comptime-only types, automatic-layout aggregates, and so on -- we still use this "hierarchical" structure. However, for types with well-defined layouts, we use a byte offset associated with the pointer. This allows the comptime pointer access logic to deal with reinterpreted pointers far more gracefully, because the "base address" of a pointer -- for instance a `field` -- is a single value which pointer accesses cannot exceed since the parent has undefined layout. This strategy is also more useful to most backends -- see the updated logic in `codegen.zig` and `codegen/llvm.zig`. For backends which do prefer a chain of field and elements accesses for lowering pointer values, such as SPIR-V, there is a helpful function in `Value` which creates a strategy to derive a pointer value using ideally only field and element accesses. This is actually more correct than the previous logic, since it correctly handles pointer casts which, after the dust has settled, end up referring exactly to an aggregate field or array element. In terms of the pointer access code, it has been rewritten from the ground up. The old logic had become rather a mess of special cases being added whenever bugs were hit, and was still riddled with bugs. The new logic was written to handle the "difficult" cases correctly, the most notable of which is restructuring of a comptime-only array (for instance, converting a `[3][2]comptime_int` to a `[2][3]comptime_int`. Currently, the logic for loading and storing work somewhat differently, but a future change will likely improve the loading logic to bring it more in line with the store strategy. As far as I can tell, the rewrite has fixed all bugs exposed by #19414. As a part of this, the comptime bitcast logic has also been rewritten. Previously, bitcasts simply worked by serializing the entire value into an in-memory buffer, then deserializing it. This strategy has two key weaknesses: pointers, and undefined values. Representations of these values at comptime cannot be easily serialized/deserialized whilst preserving data, which means many bitcasts would become runtime-known if pointers were involved, or would turn `undefined` values into `0xAA`. The new logic works by "flattening" the datastructure to be cast into a sequence of bit-packed atomic values, and then "unflattening" it; using serialization when necessary, but with special handling for `undefined` values and for pointers which align in virtual memory. The resulting code is definitely slower -- more on this later -- but it is correct. The pointer access and bitcast logic required some helper functions and types which are not generally useful elsewhere, so I opted to split them into separate files `Sema/comptime_ptr_access.zig` and `Sema/bitcast.zig`, with simple re-exports in `Sema.zig` for their small public APIs. Whilst working on this branch, I caught various unrelated bugs with transitive Sema errors, and with the handling of `undefined` values. These bugs have been fixed, and corresponding behavior test added. In terms of performance, I do anticipate that this commit will regress performance somewhat, because the new pointer access and bitcast logic is necessarily more complex. I have not yet taken performance measurements, but will do shortly, and post the results in this PR. If the performance regression is severe, I will do work to to optimize the new logic before merge. Resolves: #19452 Resolves: #19460
2024-04-13cbe: fix optional codegenJacob Young
Also reduce ctype pool string memory usage, remove self assignments, and enable more warnings.
2024-04-08InternPool: remove slice from byte aggregate keysJacob Young
This deletes a ton of lookups and avoids many UAF bugs. Closes #19485
2024-04-08cbe: fix struct field location computationJacob Young
2024-04-08cbe: remove threadlocal variables in single threaded modeJacob Young
2024-04-06Merge pull request #19562 from Snektron/spirv-remove-cacheAndrew Kelley
spirv: remove cache
2024-04-06Builder: fix encoding big integers in bitcodeJacob Young
Closes #19543
2024-04-06LLVM Builder: Emit binary op optional flags for exact and no wrapantlilja
2024-04-06spirv: yeet cacheRobin Voetter
2024-04-06spirv: remove cache usage from assemblerRobin Voetter
2024-04-06spirv: remove cache usage for typesRobin Voetter