Commit Graph

2117 Commits

Author SHA1 Message Date
Alex Rønne Petersen ed9aa8f259 compiler: Move int size/alignment functions to std.Target and std.zig.target.
This allows using them in e.g. compiler-rt.
2025-04-11 05:22:00 -04:00
Alex Rønne Petersen 0132be7bf3 std.Target: Rename charSignedness() to cCharSignedness().
To be consistent with the other functions that answer C ABI questions.
2025-04-11 05:22:00 -04:00
Alex Rønne Petersen ddcf6fcdf3 compiler: Allow using LLVM's SPIR-V backend. 2025-04-09 19:32:57 +02:00
imreallybadatnames™️ 7733b5dbe6 Merge pull request #23501 from imreallybadatnames/master
Step.Compile: use LtoMode enum for lto option
2025-04-09 05:16:36 +00:00
SuperAuguste 227788e6d5 Fix mach-o naming for sancov sections 2025-04-09 04:48:39 +02:00
SuperAuguste 36b9e56753 Remove overzealous LLVM anti-instrumentation attributes 2025-04-07 07:53:42 +02:00
Alex Rønne Petersen 0d6f3aa6c1 llvm: Remove workaround for zero-length memset/memcpy on wasm.
Closes #16360.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen 7109e462b7 llvm: Use muslabin32/muslabi64 environments in the target triple.
Closes #2909.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen 9a59cff27f llvm: Allow FastISel on mips again.
Closes #21215.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen 166766d63d llvm: never_tail implies never_inline, so set noinline in this case too. 2025-04-04 06:08:10 +02:00
Alex Rønne Petersen 858305385d llvm: Update the list of targets that use native f16/f128.
Closes #22003.
Closes #22013.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen 4c5c5bcd91 llvm: Fix i128 alignment for various targets.
This ABI bug was fixed in LLVM 20.
2025-04-04 06:08:10 +02:00
Alex Rønne Petersen 3d1cfdb365 llvm: Set target-abi module flag.
LLVM is increasingly making use of this module flag when present.
2025-04-04 06:08:09 +02:00
Alex Rønne Petersen 8954e9748a std.Target: Add Abi.muslf32 and Abi.muslsf. 2025-04-04 06:08:09 +02:00
Alex Rønne Petersen 4de368a1b6 std.Target: Update CPU models/features for LLVM 20.
Closes #21818.
2025-04-04 06:08:09 +02:00
Alex Rønne Petersen 8ea2e1ded5 compiler: Updates for LLVM/Clang 20 API changes. 2025-04-04 06:08:09 +02:00
Carl Åstholm 777215d78b Use -unknown when converting WASI/Emscripten target triples into LLVM triples
The "musl" part of the Zig target triples `wasm32-wasi-musl` and
`wasm32-emscripten-musl` refers to the libc, not really the ABI.

For WASM, most LLVM-based tooling uses `wasm32-wasi`, which is
normalized into `wasm32-unknown-wasi`, with an implicit `-unknown` and
without `-musl`.

Similarly, Emscripten uses `wasm32-unknown-emscripten` without `-musl`.

By using `-unknown` instead of `-musl` we get better compatibility with
external tooling.
2025-03-24 07:04:33 +01:00
Jacob Young 98640cbeb8 Merge pull request #23209 from jacobly0/x86_64-rewrite
x86_64: rewrite wrapping multiplication
2025-03-23 21:56:58 -04:00
Carl Åstholm f45f9649e3 Lower @returnAddress to a constant 0 in Emscripten release builds
Emscripten currently implements `emscripten_return_address()` by calling
out into JavaScript and parsing a stack trace, which introduces
significant overhead that we would prefer to avoid in release builds.

This is especially problematic for allocators because the generic parts
of `std.mem.Allocator` make frequent use of `@returnAddress`, even
though very few allocator implementations even observe the return
address, which makes allocators nigh unusable for performance-critical
applications like games if the compiler is unable to devirtualize the
allocator calls.
2025-03-23 17:13:19 -04:00
Jacob Young c5c1c8538d x86_64: rewrite wrapping multiplication 2025-03-21 21:51:08 -04:00
Jacob Young ed284c1f98 big.int: fix yet another truncate bug
Too many bugs have been found with `truncate` at this point, so it was
rewritten from scratch.

Based on the doc comment, the utility of `convertToTwosComplement` over
`r.truncate(a, .unsigned, bit_count)` is unclear and it has a subtle
behavior difference that is almost certainly a bug, so it was deleted.
2025-03-21 21:51:08 -04:00
dan 07c04bcd83 spirv: Assemble OpTypeRuntimeArray. 2025-03-19 11:45:35 +08:00
Alex Rønne Petersen 03123916e5 compiler: Support more GCC code models and fix the mapping to LLVM code models.
Closes #22517.
2025-03-19 03:15:16 +01:00
Ali Cheraghi ee06b2ce76 spirv: require int8/int16 capabilities 2025-03-18 07:05:50 +03:30
Ali Cheraghi d18eaf8586 spirv: aligned load for physical storage variables
Resolves #23212
2025-03-18 07:05:50 +03:30
Ali Cheraghi 54c097f50d spirv: packed struct init + field val access 2025-03-18 07:05:48 +03:30
Ali Cheraghi 50539a2447 spirv/target: arbitrary_precision_integers feature support 2025-03-17 21:56:17 +03:30
Ali Cheraghi e2e7577474 spirv: lower more types in assembler 2025-03-17 21:56:17 +03:30
Ali Cheraghi 78ad866dd1 target: split addresses and physical_storage_buffer features 2025-03-17 21:56:17 +03:30
Ali Cheraghi c1977bf0fb Sema: error on illegal code when targeting spirv 2025-03-17 21:56:14 +03:30
Ali Cheraghi 2fc409a32f spirv: don't hardcode test error type alignment 2025-03-17 20:19:08 +03:30
Andrew Kelley 61c588d726 Merge pull request #22998 from jacobly0/x86_64-rewrite
x86_64: rewrite aggregate init
2025-03-08 14:27:57 -05:00
Alex Rønne Petersen 5466a2f72d llvm: Replace DataLayoutBuilder with a simple target -> string switch.
This should be a lot easier to maintain. It's also a small step towards
eventually making the builder API parse the data layout string in order to
answer layout questions that we need to ask during code generation.
2025-03-08 12:16:13 +01:00
Jacob Young 54ed62755f x86_64: implement write register splitting 2025-03-07 23:59:31 -05:00
Linus Groh 79460d4a3e Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
Alex Rønne Petersen 5c44934e20 Move the compiler's LLVM bitcode builder to std.zig.llvm. 2025-02-27 01:32:49 -05:00
Robin Voetter fe5a78691f spirv: get rid of function_types cache
This deep hash map doesn't work
2025-02-24 20:58:13 +01:00
Ali Cheraghi 94af47d28c spirv: do not generate unnecessary forward pointer
Co-authored-by: Robin Voetter <robin@voetter.nl>
2025-02-24 19:12:38 +01:00
Ali Cheraghi a0eec9ce9e spirv: replace some unreachables with compile errors 2025-02-24 19:12:33 +01:00
Alex Rønne Petersen ecc76348e6 Merge pull request #22154 from alexrp/disable-intrinsics
compiler: Implement `@disableIntrinsics()` builtin function.
2025-02-24 08:25:23 +01:00
Alex Rønne Petersen 76558f8c6b llvm: Fix C ABI integer promotion for loongarch64.
It appears to just be a 1:1 copy of riscv64, including the super weird sign
extension quirk for u32.

Contributes to #21671.
2025-02-24 06:07:05 +01:00
Alex Rønne Petersen e11ac02662 cbe: Implement support for -fno-builtin and @disableIntrinsics(). 2025-02-23 04:08:58 +01:00
Alex Rønne Petersen 6ba785584a compiler: Implement @disableIntrinsics() builtin function.
Closes #21833.
Closes #22110.
2025-02-23 04:08:56 +01:00
Andrew Kelley eb3c7f5706 zig build fmt 2025-02-22 17:09:20 -08:00
Alex Rønne Petersen 5e203e157b Merge pull request #22903 from alexrp/llvm-nobuiltin-memcpy-inline
`llvm`: Use inline variants of `memcpy`/`memset` intrinsics when using `-fno-builtin`
2025-02-23 00:51:40 +01:00
Alex Rønne Petersen 21eb757497 llvm: Use inline variants of memcpy/memset intrinsics when using -fno-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.
2025-02-22 15:06:40 +01:00
Alex Rønne Petersen 41b179ca09 llvm.Builder: Update some intrinsic definitions for LLVM 19. 2025-02-22 15:06:37 +01:00
Xavier Bouchoux 84ece5624a fix -fsanitize-coverage-trace-pc-guard and fuzzer support for C compile units
- allow `-fsanitize-coverage-trace-pc-guard` to be used on its own without enabling the fuzzer.
   (note that previouly, while the flag was only active when fuzzing, the fuzzer itself doesn't use it, and the code will not link as is.)

 - add stub functions in the fuzzer to link with instrumented C code (previously fuzzed tests failed to link if they were calling into C):
   while the zig compile unit uses a custom `EmitOptions.Coverage` with features disabled,
   the C code is built calling into the clang driver with "-fsanitize=fuzzer-no-link" that automatically enables the default features.
	(see https://github.com/llvm/llvm-project/blob/de06978ebcff5f75913067b019d2d522d0be0872/clang/lib/Driver/SanitizerArgs.cpp#L587)

 - emit `-fsanitize-coverage=trace-pc-guard` instead of `-Xclang -fsanitize-coverage-trace-pc-guard` so that edge coverrage is enabled by clang driver. (previously, it was enabled only because the fuzzer was)
2025-02-21 06:06:26 +01:00
Ali Cheraghi 7872082939 spirv: extend supported c constraint values 2025-02-18 18:08:51 +03:30
Ali Cheraghi d5e1cb3ea2 spirv: ziggify and remove unknown spirv features
`OpCapability` and `OpExtension` now can also be emitted from inline assembly
2025-02-18 18:08:47 +03:30