18284 Commits

Author SHA1 Message Date
Jakub Konka
f57b059e58 regalloc: refactor locking multiple registers at once 2022-05-07 13:27:11 +02:00
Jakub Konka
bf11cdc9d8 x64: refactor code to avoid stage1 sema limitations 2022-05-07 13:19:53 +02:00
Jakub Konka
197c2a465f regalloc: rename freeze/unfreeze to lock/unlock registers 2022-05-07 10:46:05 +02:00
Jakub Konka
43a627927f x64: fix misused register locks 2022-05-07 10:31:08 +02:00
Jakub Konka
ac954eb539 regalloc: ensure we only freeze/unfreeze at the outermost scope
This prevents a nasty type of bugs where we accidentally unfreeze
a register that was frozen purposely in the outer scope, risking
accidental realloc of a taken register.

Fix CF flags spilling on aarch64 backend.
2022-05-07 00:57:55 +02:00
Jakub Konka
ac1aaec9c3 x64: handle CF flags spilling in overflow calls
Handle spilling of CF flags set with an overflow call.
Add saving stack offset to memory.
2022-05-06 13:42:11 +02:00
Jakub Konka
df38dfa4d1
Merge pull request #11591 from ziglang/x64-overflow 2022-05-06 07:28:44 +02:00
Jakub Konka
09d2b6c4e1
Merge pull request #11487 from koachan/sparc64-codegen 2022-05-06 07:27:30 +02:00
Jakub Konka
c592f0ca21 test: pass extended mul_with_overflow tests on x64 2022-05-05 22:53:11 +02:00
Jakub Konka
e3160ec573 x64: mul_with_overflow: cannot reuse operand if not the result 2022-05-05 22:51:12 +02:00
Jakub Konka
0728847ce7 x64: handle unsigned mul_with_overflow for non-pow-2 ints 2022-05-05 22:51:12 +02:00
Jakub Konka
0fc1e8b54f x64: handle signed mul_with_overflow for non-pow-2 ints 2022-05-05 22:51:12 +02:00
Jakub Konka
ebfc2825ab x64: explicitly handle Vector vs Int types for overflow arith 2022-05-05 22:51:12 +02:00
Jakub Konka
13d1798ea0
Merge pull request #11574 from ziglang/stage2-aarch64
stage2,aarch64: basic overflow arithmetic support
2022-05-05 22:50:38 +02:00
Jakub Konka
90a8817f55 aarch64: ensure we set correct operand size at codegen stage 2022-05-05 22:33:03 +02:00
Jakub Konka
eab5a1bd5a test: test bitwidths between 1...8 and 8...16 for mul_with_overflow 2022-05-05 21:43:36 +02:00
Jakub Konka
3cef23129a test: test more int sizes for @mulWithOverflow builtin 2022-05-05 21:43:36 +02:00
Jakub Konka
d112cd52f3 aarch64: fix mul_with_overflow for ints <= 32bits 2022-05-05 21:43:36 +02:00
Jakub Konka
f4421c01e8 aarch64: implement mul_with_overflow for ints in range 33-64 bits incl 2022-05-05 21:43:36 +02:00
Jakub Konka
8715b01005 aarch64: implement mul_with_overflow for <= 32bit ints
Add emitters for `smull`, `umull` and `tst (immediate)` instructions.
2022-05-05 21:43:36 +02:00
joachimschmidt557
aaacda4df9 stage2 AArch64: implement shl_with_overflow 2022-05-05 21:43:35 +02:00
joachimschmidt557
f267e7a8b4 stage2 AArch64: implement {add,sub}_with_overflow for all ints < 64 2022-05-05 21:43:35 +02:00
joachimschmidt557
c2d2307d09 stage2 AArch64: initial implementation of {add,sub}_with_overflow 2022-05-05 21:43:35 +02:00
Jakub Konka
9985699943 libstd: map sparcv9 to qemu-sparc64 for test-runner 2022-05-05 20:00:13 +02:00
Jakub Konka
64927aa782 sparcv9: fix typo in def comment 2022-05-05 19:38:55 +02:00
Koakuma
5a6f0d2e51 stage2: sparcv9: Update Mir tag doc comments 2022-05-05 19:34:06 +02:00
Koakuma
bc5b5df2c7 stage2: sparcv9: Update test case 2022-05-05 19:34:06 +02:00
Koakuma
e963d5be0b stage2: sparcv9: Simplify debug info emission, remove unused formats 2022-05-05 19:34:06 +02:00
Koakuma
c73eb00727 stage2: sparcv9: Add debug info generation for args 2022-05-05 19:34:05 +02:00
Koakuma
e76d52c74d stage2: sparcv9: Remove dbg_arg instruction 2022-05-05 19:34:05 +02:00
Koakuma
ae201807f5 stage2: sparcv9: Simplify genLoad/genStore 2022-05-05 19:34:05 +02:00
Koakuma
f6bf3dd78c stage2: sparcv9: Fix stack space accounting 2022-05-05 19:34:04 +02:00
Koakuma
e03ec51b4b stage2: sparcv9: Pad branch delay slots with nops 2022-05-05 19:34:04 +02:00
Koakuma
a00d69ea4a stage2: sparcv9: Implement basic stack load/stores 2022-05-05 19:34:04 +02:00
Koakuma
b6d7f63f34 stage2: sparcv9: Implement jmpl lowering 2022-05-05 19:34:03 +02:00
Andrew Kelley
59905a62f9
Merge pull request #11583 from ziglang/stage2-test-behavior
stage2 behavior tests for all targets passing with the LLVM backend
2022-05-05 12:53:23 -04:00
Isaac Freund
49a7ceb5bc cmake: add /usr/lib/llvm13 to searched paths
Alpine linux installs llvm to this path and currently patches zig's
cmake file in order to build zig from source.

https://git.alpinelinux.org/aports/tree/testing/zig/llvm-include.patch?id=0c3f7850bef38fb4c63fc6af5c14724e5311b0cc
2022-05-05 02:51:48 -04:00
Andrew Kelley
44252f4d35 LLVM: fix C ABI for windows
* sret logic needed a check for hasRuntimeBits()
 * lower f128 on windows targets with the "sse" class rather than
   "memory". For reference, clang emits a compile error when __float128
   is used with the MSVC ABI, saying that this type is not supported.
   The docs for the x64 calling convention have both of these sentences:
   - "Any argument that doesn't fit in 8 bytes, or isn't 1, 2, 4, or 8 bytes,
     must be passed by reference."
   - "All floating point operations are done using the 16 XMM registers."
 * For i128, however, it is clear that the Windows calling convention
   wants such an object to be passed by reference. I fixed the LLVM
   lowering for function parameters to make this work.
2022-05-04 22:57:57 -07:00
Andrew Kelley
17fc44dd12 LLVM: fix x86_64 sysv C ABI for extern structs with sub-64 bit integers 2022-05-04 21:11:55 -07:00
Andrew Kelley
1b432b5576 stage2: implement global assembly
So far it's supported by the LLVM backend only. I recommend for the
other backends to wait for the resolution of #10761 before adding
support for this feature.
2022-05-04 20:38:53 -07:00
Andrew Kelley
ba127058d1 CLI: detect MinGW-flavored static libraries
Ideally on Windows, static libraries look like "foo.lib". However, CMake
and other build systems will unfortunately produce static libraries that
instead look like "libfoo.a". This patch makes Zig's CLI resolve "-lfoo"
arguments into static libraries that match this other pattern.

This patch fixes an issue with zig-bootstrap where it won't find the
LLVM, Clang, and LLD libraries.
2022-05-04 19:15:31 -07:00
Andrew Kelley
0bebb688fb stage2: change max int align from 8 to 16 for more ISAs
These targets now have a similar disagreement with LLVM about the
alignment of 128-bit integers as x86_64:
 * riscv64
 * powerpc64
 * powerpc64le
 * mips64
 * mips64el
 * sparcv9

See #2987
2022-05-04 19:11:02 -07:00
Andrew Kelley
af7e945a7d stage2: fix @sizeOf for structs with comptime fields 2022-05-04 18:45:59 -07:00
Andrew Kelley
2f6a01d0c3 stage1: fix @sizeOf for 128-bit integer types 2022-05-04 17:34:17 -07:00
Andrew Kelley
f21c11a7f7 stage2: change x86_64 max int alignment from 8 to 16
For x86_64, LLVMABIAlignmentOfType(i128) reports 8. However I think 16
is a better number for two reasons:
1. Better machine code when loading into SIMD register.
2. The C ABI wants 16 for extern structs.
2022-05-04 17:34:17 -07:00
Andrew Kelley
5b1c0d922c stage2: improve semantics of atomic operations
ZIR instructions updated: atomic_load, atomic_rmw, atomic_store, cmpxchg
These no longer construct a pointer type as the result location. This
solves a TODO that was preventing the pointer from possibly being
volatile, as well as properly handling allowzero and addrspace.
It also allows the pointer to be over-aligned, which may be needed
depending on the target. As a consequence, the element type needs to be
communicated in the ZIR. This is done by strategically making one of the
operands be ResultLoc.ty instead of ResultLoc.coerced_ty if possible, or
otherwise explicitly adding elem_type into the ZIR encoding, such as in
the case of atomic_load.

The pointer type of atomic operations is now checked in Sema by coercing
it to an expected pointer type, that maybe over-aligned according to
target requirements.

Together with the previous commit, Zig now has smaller alignment for
large integers, depending on the target, and yet still has type safety
for atomic operations that specially require higher alignment.
2022-05-04 17:34:16 -07:00
Andrew Kelley
259f784241 stage2: improve @sizeOf and @alignOf integers
Prior to this commit, the logic for ABI size and ABI alignment for
integers was naive and incorrect. This results in wasted hardware as
well as undefined behavior in the LLVM backend when we memset an
incorrect number of bytes to 0xaa due to disagreeing with LLVM about the
ABI size of integers.

This commit introduces a "max int align" value which is different per
Target. This value is used to derive the ABI size and alignment of all
integers.

This commit makes an interesting change from stage1, which treats
128-bit integers as 16-bytes aligned for x86_64-linux. stage1 is
incorrect. The maximum integer alignment on this system is only 8 bytes.
This change breaks the behavior test called "128-bit cmpxchg" because on
that target, 128-bit cmpxchg does require a 16-bytes aligned pointer to
a 128 bit integer. However, this alignment property does not belong on
*all* 128 bit integers - only on the pointer type in the `@cmpxchg`
builtin function prototype. The user can then use an alignment override
annotation on a 128-bit integer variable or struct field to obtain such
a pointer.
2022-05-04 17:34:16 -07:00
Andrew Kelley
080e870a71
Merge pull request #11572 from ziglang/test-harness
test: improve test/batch sequence iterator and move all tests into cases/ parent dir
2022-05-04 20:28:34 -04:00
Jakub Konka
3624e1ef48 test: move compile errors and incremental tests into common dir 2022-05-04 23:51:16 +02:00
Jakub Konka
9d79b740bc test: improve test batch/sequence iterator
With this improved iterator, type of test is now inferred from
the filename, enabling us to put all cases in one common parent
directory, and iterate over that, thus automating a lot of tasks.
2022-05-04 23:21:35 +02:00