471 Commits

Author SHA1 Message Date
Andrew Kelley
d604553ee0 C backend: use ++ instead of += for airMemset
It does the same thing but has fewer bytes in the output.
2023-04-25 11:23:41 -07:00
Andrew Kelley
0f65cc9275 C backend: fix memset for loop lowering
Previously, this code casted the array pointer to u8 pointer, but I
removed that in a different commit. This commit restores the cast, but
instead of hard-coding u8, it uses the destination element pointer,
since memset now supports arbitrary element types.
2023-04-25 11:23:41 -07:00
Andrew Kelley
057c950093 LLVM backend: support non-byte-sized memset
Also introduce memset_safe AIR tag and support it in C backend and LLVM
backend.
2023-04-25 11:23:41 -07:00
Andrew Kelley
92186b8c13 C backend: implement new memcpy and inttoptr semantics 2023-04-25 11:23:40 -07:00
Andrew Kelley
edb5e493e6 update @memcpy to require equal src and dest lens
* Sema: upgrade operands to array pointers if possible when emitting
   AIR.
 * Implement safety checks for length mismatch and aliasing.
 * AIR: make ptrtoint support slice operands. Implement in LLVM backend.
 * C backend: implement new `@memset` semantics. `@memcpy` is not done
   yet.
2023-04-25 11:23:40 -07:00
Jacob Young
08a8aa100d cbe: fix local aliasing issues in atomic ops 2023-04-21 23:08:48 -04:00
Jacob Young
5feb27c126 zig.h: fix float negation 2023-04-21 23:08:48 -04:00
Jacob Young
d56c6c7791 cbe: implement 128-bit atomics support
* Disable 128-bit atomics for x86_64 generic (currently also baseline)
   because they require heavy abi agreement to correctly lower.
   ** This is a breaking change **
 * Enable 128-bit atomics for aarch64 in Sema since it just works.
2023-04-21 16:36:31 -04:00
Jacob Young
a519c9dace cbe: fix atomic float min/max
These need `zig_atomic`, unlike int min/max.
2023-04-21 16:36:31 -04:00
Jacob Young
e364627e3e cbe: fix float casts involving f16
Fixes bugs with a previous fix to the f16 abi on x86 darwin.
2023-04-21 16:36:31 -04:00
Jacob Young
a1ed4bd796 cbe: fix remaining aarch64 issues 2023-04-21 16:36:31 -04:00
Jacob Young
d98974e826 cbe: fix issues with atomic floats
Since the Zig language documentation claims support for `.Min` and
`.Max` in `@atomicRmw` with floats, allow in Sema and implement for both
the llvm and C backends.
2023-04-21 16:36:30 -04:00
Jacob Young
bf6fd9ae3f cbe: enable CI for std tests 2023-04-21 16:36:10 -04:00
mlugg
6fc524de42
cbe: integrate new Liveness behaviour 2023-04-20 20:49:34 +01:00
mlugg
8258530c39
Liveness: control flow analysis
This is a partial rewrite of Liveness, so has some other notable changes:
- A proper multi-pass system to prevent code duplication
- Better logging
- Minor bugfixes
2023-04-20 20:28:04 +01:00
Jacob Young
a7f674d6c1
cbe: assert there are no unfreed locals
Also fix the many revealed bugs.
2023-04-07 01:29:20 +01:00
mlugg
1059b57898
Liveness: defer deaths of externally-scoped instructions in loop bodies 2023-04-07 01:29:20 +01:00
Andrew Kelley
f289277599 Merge remote-tracking branch 'origin/master' into llvm16 2023-04-05 22:05:31 -07:00
Jacob Young
243848167b compiler_rt: attempt to fix f16 abi on mac with llvm 16 2023-04-05 22:05:06 -07:00
Jacob Young
f4b411314c Sema: defer stores to inferred allocs
This lets us generate the store with knowledge of the type to be stored.
Therefore, we can avoid generating garbage Air with stores through
pointers to comptime-only types which backends cannot lower.

Closes #13410
Closes #15122
2023-04-02 18:05:44 +03:00
Robin Voetter
3357c59ceb new builtins: @workItemId, @workGroupId, @workGroupSize
* @workItemId returns the index of the work item in a work group for a
  dimension.
* @workGroupId returns the index of the work group in the kernel dispatch for a
  dimension.
* @workGroupSize returns the size of the work group for a dimension.

These builtins are mainly useful for GPU backends. They are currently only
implemented for the AMDGCN LLVM backend.
2023-03-30 12:20:24 +03:00
Jacob Young
dd66e0addb Sema: fix empty slice pointer value
We just checked that inst_child_ty was effectively a zero-bit type, so
it is certainly not the non-zero alignment we are looking for.

Closes #15085
2023-03-28 23:12:19 +03:00
Xavier Bouchoux
898e4473e8 CBE: implement aggregateInit() for array of array case.
fixes `error(compilation): clang failed with stderr: error: array type 'uint32_t[10]' (aka 'unsigned int[10]') is not assignable`
2023-03-21 14:56:04 +02:00
Jacob Young
77d06012c2 CBE: implement unsigned big int div and mod 2023-03-07 03:03:35 -05:00
Jacob Young
1efd36cd5c CBE: fix reduce of emulated integers 2023-03-05 06:32:55 -05:00
Jacob Young
33fa25ba44 CBE: ensure uniqueness of more internal identifiers 2023-03-05 02:59:02 -05:00
Jacob Young
0b0298aff2 CBE: implement select and shuffle 2023-03-05 02:59:02 -05:00
Jacob Young
aac4707902 CBE: implement splat 2023-03-05 02:59:02 -05:00
Jacob Young
ba69ee488b CBE: implement vector truncate 2023-03-05 02:59:02 -05:00
Jacob Young
8f6da78fb1 CBE: implement vector element pointers 2023-03-05 02:59:02 -05:00
Jacob Young
c478c7609e CBE: implement vector operations
Also, bigint add and sub which is all I was actually trying to do.
2023-03-05 02:59:02 -05:00
Jacob Young
9e3a5ecd39 CBE: fix behavior test failures on msvc 2023-03-05 02:59:02 -05:00
Jacob Young
93d696e84e CBE: implement some big integer and vector unary operations 2023-03-05 02:59:01 -05:00
Jacob Young
a8f4ac2b94 CBE: implement big integer and vector comparisons 2023-03-05 02:59:01 -05:00
Jacob Young
874ae81f1b CBE: implement big integer literals 2023-03-05 02:59:01 -05:00
r00ster91
65368683ad add @trap builtin
This introduces a new builtin function that compiles down to something that results in an illegal instruction exception/interrupt.
It can be used to exit a program abnormally.

This implements the builtin for all backends.
2023-03-04 12:08:19 +01:00
Jacob Young
477be90c0c CBE: replace locals list with a hash map
Replace `ArrayList` with `ArrayHashMap` since we want to be able to
remove by element.
2023-02-25 00:27:07 -05:00
Jacob Young
1453a595aa CBE: reuse locals with the same CType instead of Type
Many `Type`s can correspond to the same `CType`, so this reduces the
number of used locals by 27760 when compiling only-c.

Also, disabled some tests that were only passing by accident and
shouldn't really be considered working.
2023-02-24 23:41:54 -05:00
Jacob Young
f8aecef670 CBE: implement the future
Turns out f(...) will be supported one day.
2023-02-23 21:25:29 -05:00
Jacob Young
1f3d9f79c1 CBE: apply some maybe payload cleanups 2023-02-23 20:30:59 -05:00
Jacob Young
c0671a92c7 CBE: simplify always_tail call logic
It should be Sema's job to check this anyway.
2023-02-23 20:30:59 -05:00
Jacob Young
3a1cb62317 CBE: delete stage1 hacks 2023-02-23 20:30:59 -05:00
Jacob Young
9d24d0354f CBE: fix MSVC diagnostics generated by the behavior tests
After this, the last MSVC warnings are in behavior/bugs/529.zig:
behavior.c(37971): warning C4133: 'function': incompatible types - from 'A__8479 *' to 'A__8474 *'
behavior.c(37974): warning C4133: 'function': incompatible types - from 'A__8480 *' to 'A__8474 *'
2023-02-23 20:30:59 -05:00
Jacob Young
a0d7fd162b CBE: support call attributes
* Support always_tail and never_tail/never_inline with a comptime callee using clang
 * Support never_inline using gcc
 * Support never_inline using msvc

Unfortunately, can't enable behavior tests because of the conditional support.
2023-02-23 10:54:26 -05:00
Jacob Young
57f6adf85d CBE: implement c varargs
Removed some backend test skip checks for things disabled in std.
2023-02-23 01:21:59 -05:00
Jacob Young
bdb1e014a0 CBE: cleanup field access
* Implement @fieldParentPtr on a union
 * Refactor field access to ensure that it is handled consistently
 * Remove `renderTypecast` as it is now behaves the same as `renderType`
2023-02-23 00:29:23 -05:00
Andrew Kelley
c9e02d3e69
Merge pull request #14691 from jacobly0/ctype 2023-02-22 11:06:13 -05:00
Jacob Young
248fb40dcc CBE: fix windows test failures 2023-02-21 15:46:34 -05:00
Isaac Freund
05da5b32a8 Sema: implement @fieldParentPtr for unions 2023-02-21 15:57:13 +02:00
Jacob Young
25a3c933b9 CBE: fix test failures 2023-02-21 02:32:49 -05:00