1143 Commits

Author SHA1 Message Date
Alex Rønne Petersen
bf9b15ee67 std.Target: Add Cpu.Arch.or1k and basic target info. 2025-05-03 11:22:27 +02:00
samy007
c0ec264f75 inline assembly: implement gcc's "%=" syntax 2025-05-02 23:09:39 +02:00
Pavel Verigo
a843be44a0 wasm-c-abi: llvm fix struct handling + reorganize
I changed to `wasm/abi.zig`, this design is certainly better than the previous one. Still there is some conflict of interest between llvm and self-hosted backend, better design will appear when abi tests will be tested with self-hosted.

Resolves: #23304
Resolves: #23305
2025-05-01 18:10:36 -04:00
Alex Rønne Petersen
fc55c1b7a1
Merge pull request #23698 from alexrp/goff-xcoff-stubs
`link`: Stub out GOFF/XCOFF linker code based on LLVM
2025-04-28 07:50:37 +02:00
Alex Rønne Petersen
e7b46363ae std.Target: Remove Os.Tag.elfiamcu.
The last Intel Quark MCU was released in 2015. Quark was announced to be EOL in
2019, and stopped shipping entirely in 2022.

The OS tag was only meaningful for Intel's weird fork of Linux 3.8.7 with a
special ABI that differs from the regular i386 System V ABI; beyond that, the
CPU itself is just a plain old P54C (i586). We of course keep support for the
CPU itself, just not Intel's Linux fork.
2025-04-28 00:24:09 +02:00
Andrew Kelley
1b76d4c53a
Merge pull request #22605 from dweiller/memmove
add `@memmove` builtin
2025-04-27 14:39:21 -04:00
Alex Rønne Petersen
5502a820e8
llvm: Fix data layout string for s390x-zos. 2025-04-27 03:54:32 +02:00
Alex Rønne Petersen
23440fbb99 std.Target: Remove Abi.gnuilp32.
* This has not seen meaningful development for about a decade.
* The Linux kernel port was never upstreamed.
* The glibc port was never upstreamed.
* GCC 15.1 recently deprecated support it.

It may still make sense to support an ILP32 ABI on AArch64 more broadly (which
we already have the Abi.ilp32 tag for), but, to the extent that it even existed
in any "official" sense, the *GNU* ILP32 ABI is certainly dead.
2025-04-26 22:12:31 +02:00
dweiller
898ca82458 compiler: add @memmove builtin 2025-04-26 13:34:16 +10: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
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
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
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
Alex Rønne Petersen
5c44934e20 Move the compiler's LLVM bitcode builder to std.zig.llvm. 2025-02-27 01:32:49 -05: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
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 de06978ebc/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
Alex Rønne Petersen
481b7bf3f0
std.Target: Remove functions that just wrap component functions.
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look
at multiple components of the target. But functions like isWasm(), isDarwin(),
isGnu(), etc only exist to save 4-8 characters. I don't think this is a good
enough reason to keep them, especially given that:

* It's not immediately obvious to a reader whether target.isDarwin() means the
  same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar
  functions *do* look at multiple components.
* It's not clear where we would draw the line. The logical conclusion before
  this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(),
  Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand.
* It's nice to just have a single correct way of doing something.
2025-02-17 19:18:19 +01:00
Alex Rønne Petersen
aa4ac2f85f
std.builtin: Rename CallingConvention.propeller1_sysv to propeller_sysv. 2025-02-17 19:17:56 +01:00
Alex Rønne Petersen
e0f8d4e68e
std.builtin: Rename CallingConvention.wasm_watc to wasm_mvp. 2025-02-17 19:17:56 +01:00
Alex Rønne Petersen
9c015e6c2b
std.builtin: Remove CallingConvention.arm_(apcs,aapcs16_vfp).
* arm_apcs is the long dead "OABI" which we never had working support for.
* arm_aapcs16_vfp is for arm-watchos-none which is a dead target that we've
  dropped support for.
2025-02-17 19:17:56 +01:00
Alex Rønne Petersen
2fe32ef847
std.Target: Remove Cpu.Arch.propeller2 and use a CPU feature instead. 2025-02-17 19:17:55 +01:00
Alex Rønne Petersen
b541a7af11
std.Target: Remove Cpu.Arch.spu_2.
This was for a hobby project that appears to be dormant for now. This can be
added back if the project is resumed in the future.
2025-02-17 19:17:55 +01:00
Jacob Young
afa74c6b21 Sema: introduce all_vector_instructions backend feature
Sema is arbitrarily scalarizing some operations, which means that when I
try to implement vectorized versions of those operations in a backend,
they are impossible to test due to Sema not producing them. Now, I can
implement them and then temporarily enable the new feature for that
backend in order to test them. Once the backend supports all of them,
the feature can be permanently enabled.

This also deletes the Air instructions `int_from_bool` and
`int_from_ptr`, which are just bitcasts with a fixed result type, since
changing `un_op` to `ty_op` takes up the same amount of memory.
2025-01-31 23:00:34 -05:00
mlugg
b01d6b156c compiler: add intcast_safe AIR instruction
This instruction is like `intcast`, but includes two safety checks:

* Checks that the int is in range of the destination type
* If the destination type is an exhaustive enum, checks that the int
  is a named enum value

This instruction is locked behind the `safety_checked_instructions`
backend feature; if unsupported, Sema will emit a fallback, as with
other safety-checked instructions.

This instruction is used to add a missing safety check for `@enumFromInt`
truncating bits. This check also has a fallback for backends which do
not yet support `safety_checked_instructions`.

Resolves: #21946
2025-01-30 14:47:59 +00:00
mlugg
83991efe10
compiler: yet more panic handler changes
* `std.builtin.Panic` -> `std.builtin.panic`, because it is a namespace.
* `root.Panic` -> `root.panic` for the same reason. There are type
  checks so that we still allow the legacy `pub fn panic` strategy in
  the 0.14.0 release.
* `std.debug.SimplePanic` -> `std.debug.simple_panic`, same reason.
* `std.debug.NoPanic` -> `std.debug.no_panic`, same reason.
* `std.debug.FormattedPanic` is now a function `std.debug.FullPanic`
  which takes as input a `panicFn` and returns a namespace with all the
  panic functions. This handles the incredibly common case of just
  wanting to override how the message is printed, whilst keeping nice
  formatted panics.
* Remove `std.builtin.panic.messages`; now, every safety panic has its
  own function. This reduces binary bloat, as calls to these functions
  no longer need to prepare any arguments (aside from the error return
  trace).
* Remove some legacy declarations, since a zig1.wasm update has
  happened. Most of these were related to the panic handler, but a quick
  grep for "zig1" brought up a couple more results too.

Also, add some missing type checks to Sema.

Resolves: #22584

formatted -> full
2025-01-24 19:29:51 +00:00
mlugg
1bce01de97 compiler: pass error return traces everywhere 2025-01-22 02:22:56 -05:00
mlugg
0ec6b2dd88 compiler: simplify generic functions, fix issues with inline calls
The original motivation here was to fix regressions caused by #22414.
However, while working on this, I ended up discussing a language
simplification with Andrew, which changes things a little from how they
worked before #22414.

The main user-facing change here is that any reference to a prior
function parameter, even if potentially comptime-known at the usage
site or even not analyzed, now makes a function generic. This applies
even if the parameter being referenced is not a `comptime` parameter,
since it could still be populated when performing an inline call. This
is a breaking language change.

The detection of this is done in AstGen; when evaluating a parameter
type or return type, we track whether it referenced any prior parameter,
and if so, we mark this type as being "generic" in ZIR. This will cause
Sema to not evaluate it until the time of instantiation or inline call.

A lovely consequence of this from an implementation perspective is that
it eliminates the need for most of the "generic poison" system. In
particular, `error.GenericPoison` is now completely unnecessary, because
we identify generic expressions earlier in the pipeline; this simplifies
the compiler and avoids redundant work. This also entirely eliminates
the concept of the "generic poison value". The only remnant of this
system is the "generic poison type" (`Type.generic_poison` and
`InternPool.Index.generic_poison_type`). This type is used in two
places:

* During semantic analysis, to represent an unknown result type.
* When storing generic function types, to represent a generic parameter/return type.

It's possible that these use cases should instead use `.none`, but I
leave that investigation to a future adventurer.

One last thing. Prior to #22414, inline calls were a little inefficient,
because they re-evaluated even non-generic parameter types whenever they
were called. Changing this behavior is what ultimately led to #22538.
Well, because the new logic will mark a type expression as generic if
there is any change its resolved type could differ in an inline call,
this redundant work is unnecessary! So, this is another way in which the
new design reduces redundant work and complexity.

Resolves: #22494
Resolves: #22532
Resolves: #22538
2025-01-21 02:41:42 +00:00
Jacob Young
5cfcb01503 llvm: convert @divFloor and @mod to forms llvm will recognize
On x86_64, the `@divFloor` change is a strict improvement, and the
`@mod` change adds one zero latency instruction.  In return, once we
upgrade to LLVM 20, when the optimizer discovers one of these operations
has a power-of-two constant rhs, it will be able to optimize the entire
operation into an `ashr` or `and`, respectively.

                      #I   CPL   CPT
    old `@divFloor` |  8 | 15 | .143 |
    new `@divFloor` |  7 | 15 | .148 |
    old `@mod`      |  9 | 17 | .134 | (rip llvm
    new `@mod`      | 10 | 17 | .138 |  scheduler)
2025-01-19 22:10:39 -05:00