1202 Commits

Author SHA1 Message Date
Robin Voetter
e26d8d0604
spirv: make decl deps a hash map instead of an arraylist
The same declaration can be added to the dependency set multiple
times, and in this case we still need to emit it once. By making
this list a hash map instead, we can do that quite easily.

This commit also introduces some additional debug logging regarding
decls.
2023-05-11 20:31:51 +02:00
Robin Voetter
d961b11cde
spirv: lower wrap_optional
This implements the wrap_optional AIR instruction.
2023-05-11 20:31:51 +02:00
Robin Voetter
6c16465d45
spirv: lower air optional_payload
Implements lowering the AIR tag optional_payload.

Also fixes an issue with lowering constant ints.
2023-05-11 20:31:51 +02:00
Robin Voetter
83ab1ba8fd
spirv: lower air is_null, is_non_null
Implements AIR lowering for is_null and is_non_null tags.

Additionally this cleans up and centralizes the logic to convert from 'direct'
representation to 'indirect' representation and vice-versa. The related functions,
as well as the functions that use it, are all moved near eachother so that the
conversion logic remains in a central place. Extracting/inserting fields
and loading/storing pointers should go through these functions.
2023-05-11 20:31:51 +02:00
Robin Voetter
435a5660ce
spirv: fix invalid code generated by br-with-value
The result-id and result-type-id of the OpPhi used to merge the
break values was not properly emitted, as some of the operands
were not written out. This caused an invalid spir-v module.
2023-05-11 20:31:51 +02:00
Robin Voetter
f62735d98c
spirv: lower air wrap_errunion_err 2023-05-11 20:31:51 +02:00
Robin Voetter
78c44d63da
spirv: lower air unwrap_error_union_err 2023-05-11 20:31:50 +02:00
Robin Voetter
0bae2caaf3
spirv: lower air try
Implements code generation for the try air tag. This commit also adds
a utility `errorUnionLayout` function that helps keeping the layout
of a spir-v error union consistent.
2023-05-11 20:31:50 +02:00
Robin Voetter
dfecf89d06
spirv: fix OpFunctionCall parameters interleaving with insts
resolve() is now able to emit instructions. If usage of this function is
interleaved with calls to emitRaw() and writeOperand(), then an
instruction may get inserted between operands, causing an invalid module.
The solution here is to just perform a temporary allocation.
2023-05-11 20:31:50 +02:00
Robin Voetter
5d896a6cc6
spirv: fix use-after-realloc in resolveType()
The pointer to a slot in a hash map was fetched before a recursive call.
If the hash map's size changed during the recursive call, this would write
to an invalid pointer.

The solution is to use an index instead of a pointer. Note that care must be
taken that resolved types (from the type_cahce) must not be accessed, as they
might be incomplete during this operation.
2023-05-11 20:31:50 +02:00
Andrew Kelley
5569e6b49d
Merge pull request #15639 from jacobly0/signed-mod
llvm/cbe: fix signed `@mod`/`@divFloor` computations
2023-05-11 08:36:33 -07:00
Jacob Young
c5b96c7447 llvm: fix @max/@min of unsupported float types
Closes #15611
2023-05-10 15:16:50 -04:00
Jacob Young
2e6a6d7564 llvm/cbe: fix signed @mod/@divFloor computations
Closes #15636
2023-05-10 15:11:52 -04:00
Jacob Young
31a13ce2e3 cbe: use Assignment in airSplat 2023-05-10 15:11:52 -04:00
Jacob Young
d71a43ec2c cbe: fix typos 2023-05-06 10:27:39 -07:00
Andrew Kelley
cb9e8b0d01 C backend: take advantage of Assignment abstraction in airMemset 2023-04-28 13:24:43 -07:00
Andrew Kelley
73d3fb9883 C backend: fix ptr comparison of array ptrs when one is null-terminated 2023-04-28 13:24:43 -07:00
Andrew Kelley
6261c13731 update codebase to use @memset and @memcpy 2023-04-28 13:24:43 -07:00
Andrew Kelley
36df2a83fc C backend: fix memset for structs and arrays 2023-04-28 13:24:42 -07:00
Andrew Kelley
9295355985 LLVM backend: optimize memset with comptime-known element
When the element is comptime-known, we can check if it has a repeated
byte representation. In this case, `@memset` can be lowered with the
LLVM intrinsic rather than with a loop.
2023-04-28 13:24:42 -07:00
Andrew Kelley
51adbf472b llvm backend: fix memset with byref element value 2023-04-28 13:24:42 -07:00
Andrew Kelley
00b690540e llvm backend: fix lowering of memset
The bitcast of ABI size 1 elements was problematic for some types.
2023-04-28 13:24:42 -07:00
Andrew Kelley
afbcad9939
Merge pull request #15452 from mlugg/zig-cbe-opt
CBE: minor optimizations to output source
2023-04-26 17:09:04 -07:00
Andrew Kelley
3c66850e42
Merge pull request #15278 from ziglang/memcpy-memset
change semantics of `@memcpy` and `@memset`
2023-04-26 10:01:54 -07:00
mlugg
2e23ddbe7b
CBE: minor optimizations to output source 2023-04-26 01:46:09 +01:00
Andrew Kelley
badad16f88 C backend: fix lowering comparison when array ptr meets ptr
Pointer comparisons were triggering `-Wcompare-distinct-pointer-types`
before this fix, which adds `(void*)` casts if the lhs type and rhs type
do not match pointer sizeness.
2023-04-25 11:23:41 -07:00
Andrew Kelley
792bbfa301 Sema: fix memcpy alias safety incorrect math
Previously it was not multiplying by the element ABI size. Now, it uses
ptr_add instructions which do math based on the element type.
2023-04-25 11:23:41 -07:00
Andrew Kelley
5378fdffdc stage2: introduce store_safe AIR instruction
store:
The value to store may be undefined, in which case the destination
memory region has undefined bytes after this instruction is
evaluated. In such case ignoring this instruction is legal
lowering.

store_safe:
Same as `store`, except if the value to store is undefined, the
memory region should be filled with 0xaa bytes, and any other
safety metadata such as Valgrind integrations should be notified of
this memory region being undefined.
2023-04-25 11:23:41 -07:00
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
Andrew Kelley
a5c910adb6 change semantics of @memcpy and @memset
Now they use slices or array pointers with any element type instead of
requiring byte pointers.

This is a breaking enhancement to the language.

The safety check for overlapping pointers will be implemented in a
future commit.

closes #14040
2023-04-25 11:23:40 -07:00
Jacob Young
a1fcb51692 cbe: fix mutability issues with builtin test_functions 2023-04-25 13:42:10 -04:00
Jacob Young
f1782c07a9 cbe: implement @extern 2023-04-25 13:42:10 -04:00
Jacob Young
e485d00621 cbe: remove unused arena 2023-04-25 13:42:10 -04: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
Andrew Kelley
528b66f6ec
Merge pull request #15355 from mlugg/feat/liveness-control-flow
Liveness: control flow analysis and other goodies
2023-04-21 13:32:25 -07:00
Andrew Kelley
ceff278202 fixes to the previous commit
* CompileStep: Avoid calling producesPdbFile() to determine whether the
   option should be respected. If the user asks for it, put it on the
   command line and let the Zig CLI deal with it appropriately.
 * Make the namespace of `std.dwarf.Format.dwarf32` no longer have a
   redundant "dwarf" in it.
 * Add `zig cc` integration for `-gdwarf32` and `-gdwarf64`.
 * Toss in a bonus bug fix for `-gdwarf-2`, `-gdwarf-3`, etc.
 * Avoid using default init values for struct fields unnecessarily.
 * Add missing cache hash addition for the new option.
2023-04-20 15:17:07 -07:00
David Gonzalez Martin
d026202a26 Expose an option for producing 64-bit DWARF format
This commit enables producing 64-bit DWARF format for Zig executables
that are produced through the LLVM backend. This is achieved by exposing
both command-line flags and CompileStep flags. The production of the
64-bit format only affects binaries that use the DWARF format and it is
disabled on MacOS due to it being problematic. This commit, despite
generating the interface for the Zig user to be able to tell the compile
which format is wanted, is just implemented for the LLVM backend, so
clang and the self-hosted backends will need this to be implemented in a
future commit.

This is an effort to work around #7962, since the emission of the 64-bit
format automatically produces 64-bit relocations. Further investigation
will be needed to make DWARF 32-bit format to emit bigger relocations
when needed and not make the linker angry.
2023-04-20 14:46:53 -07:00
mlugg
6f09a7041e
Begin integrating new liveness analysis into remaining backends 2023-04-20 20:49:34 +01:00
mlugg
6fc524de42
cbe: integrate new Liveness behaviour 2023-04-20 20:49:34 +01:00