489 Commits

Author SHA1 Message Date
Veikka Tuominen
3981250b84 aarch64 C ABI: return union instead of array of two enums
The result is much cleaner and the second element was unused most of the time.
2022-10-21 20:30:45 +03:00
Veikka Tuominen
9ae78a5890 stage2: implement ARM C ABI
Six new passing tests and the previously incorrectly passing
complex tests are now skipped.
2022-10-21 18:07:11 +03:00
Veikka Tuominen
972c39e2c0
Merge pull request #13219 from Vexu/stage2-fixes
Stage2 bug fixes
2022-10-21 12:11:49 +02:00
Veikka Tuominen
646d927c79 stage2: fix handling of aarch64 C ABI float array like structs
Closes #11702
Closes #13125
2022-10-20 20:11:12 +03:00
Ali Chraghi
ca27055cda all: rename @maximum to @max and @minimum to @min 2022-10-18 14:15:16 +03:00
Jacob Young
1e963053d0 tools: add lldb stage2 pretty printers
* Fix untagged struct names in debug info for llvm.
 * Factor out common stage2 pretty printer data.
 * Add lldb version of stage2 pretty printers.
2022-10-17 07:55:28 -04:00
Jacob Young
f9192adaba llvm: fix lowering of non-byte-aligned field pointers
* When a field starts at some bit offset within a byte you need to load
   starting from that byte and shift, not starting from the next byte,
   so a rounded-down divide is required here, not a rounded-up one.
 * Remove paragraph from doc that no longer relates to anything.

Closes #12363
2022-10-15 14:19:40 -04:00
Jacob Young
cb0e22db4e llvm: fix lowering of runtime refs to comptime-only decls
When we want a runtime pointer to a zero-bit value we use an undef
pointer, but what if we want a runtime pointer to a comptime-only value?
Normally, if `T` is a comptime-only type such as `*const comptime_int`,
then `*const T` would also be a comptime-only type, so anything
referencing a comptime-only value is usually also comptime-only, and
therefore not emitted to the executable.

However, what if instead we have a `*const anyopaque` pointing to a
comptime-only value?  Certainly, `*const anyopaque` is a runtime type,
and so we need some runtime value to store, even when it happens to be
pointing to a comptime-only value.  In this case we want to do the same
thing as we do when pointing to a zero-bit value, so we use
`hasRuntimeBits` to handle both cases instead of ignoring comptime.

Closes #12025
2022-10-15 14:17:25 -04:00
Andrew Kelley
66d6183001 Merge branch 'amdgpu-improvements' of https://github.com/Snektron/zig into Snektron-amdgpu-improvements 2022-10-15 10:36:10 -07:00
Jacob Young
400319872b llvm: fix bug lowering aggregate_init with a byref sentinel
Closes #12972
2022-10-15 11:12:04 -04:00
Andrew Kelley
b4e3424594
Merge pull request #13100 from topolarity/powerpc64le
stage2: Fix softfloat support for PPC64(LE)
2022-10-15 10:05:00 -04:00
Jacob Young
9b45dc1608 stage2: fix emitting asm and bin at the same time
This logic is copied from stage1.

Fixes #12800
2022-10-14 14:46:50 -04:00
Cody Tapscott
46fb730712 stage2: Use softfloat for f16 on MIPS targets 2022-10-13 12:53:20 -07:00
Cody Tapscott
db9058e41a Disable llvm.prefetch for PowerPC
This instruction is not supported on this backend, so should
just be a noop.
2022-10-13 12:53:20 -07:00
Cody Tapscott
f0d12dd82b stage2: Add softfloat support for @reduce 2022-10-13 12:53:20 -07:00
Cody Tapscott
37c6fcafa2 stage2 LLVM: Correct long double for WASM
Also, f16 is not supported on this backend.
2022-10-13 12:53:20 -07:00
Cody Tapscott
aedafb20cf stage2: Fix softfloat support for PPC64(LE)
Stage 2's softfloat support still had a couple of gaps, which were
preventing us from lowering `f16` on this target. With any luck,
this is enough to get PPC64 working as a Tier 2 target again.
2022-10-13 12:53:20 -07:00
Robin Voetter
e90a42a808
stage2: improve globals with address spaces a little 2022-10-12 20:36:15 +02:00
Robin Voetter
8894d1c45e
stage2: f128 improvements for targets that do not support it 2022-10-12 20:36:14 +02:00
Robin Voetter
5d429b03e3
stage2: add @addrSpaceCast builtin 2022-10-12 20:36:12 +02:00
Robin Voetter
5f3b91437f
stage2: improve addrspace handling
This commit changes the way Zig is intended to deal with variable
declaration for exotic targets. Where previously the idea was to
enfore local/global variables to be placed into their respective
address spaces, depending on the target, this is now fixed to the
generic address space.

To facilitate this for targets where local variables _must_ be
generated into a specific address space (ex. amdgcn where locals
must be generated into the private address space), the variable
allocations (alloca) are generated into the right address space
and then addrspace-casted back to the generic address space. While this
could be less efficient in theory, LLVM will hopefull deal with figuring
out the actual correct address space for a pointer for us. HIP seems to
do the same thing in this regard.

Global variables are handled in a similar way.
2022-10-12 20:34:42 +02:00
Robin Voetter
3392de87dc
allow global/local/shared address spaces on amdgcn 2022-10-12 20:34:41 +02:00
Robin Voetter
6b69dcfdd2
amdgpu: add AmdgpuKernel calling convention 2022-10-12 20:34:41 +02:00
jacobly0
562ac8be48
codegen: add support for lowering .field_ptr on a slice
Closes #13068
2022-10-12 12:40:59 +03:00
Cody Tapscott
e6ebdcb82e stage2 LLVM: Use a packed aggregate for union payload init
Without the packed qualifier, the type layout that we use to
initialize doesn't match the correct layout of the underlying
storage, causing corrupted data and past-the-end writes.
2022-10-11 15:42:01 -04:00
Andrew Kelley
54eb0f2daa
Merge pull request #13032 from jacobly0/br-on-undef-val
stage2: fix branches on undefined values
2022-10-03 22:46:22 -04:00
Jacob Young
38bd2bbcf2 stage2: fix C ABI for bool
This fixes a miscompilation compiling debug zig with release stage3 zig.
2022-10-03 22:41:07 -04:00
Jacob Young
272e31227c llvm: add assert to reliably catch undefined value use
This assert makes it possible to detect a regression of #13030 in the
future without relying on undefined value tracking.
2022-10-01 09:03:28 -04:00
Jacob Young
b7bd44a654 Sema: ensure builtin.StackTrace fields are analyzed
When encountering a fn type that returns an error (union), a backend
that supports error return tracing will want the StackTrace struct and
its fields to be analyzed.
2022-10-01 08:09:43 -04:00
Jacob Young
8b66443d50 llvm: avoid undefined values by ensuring the StackTrace decl is analyzed
The test builds an object file to prevent StackTrace from already having
been analyzed by other code.

Fixes #13030
2022-10-01 04:02:09 -04:00
Cody Tapscott
e165b8b223 stage2: Fix multiple_llvm_int parameter passing
Small iteration oopsie

We could really use some more comprehensive C ABI tests.
2022-09-28 12:48:28 +03:00
Jakub Konka
9c2fb6e186
Merge pull request #12959 from kcbanner/fix_uwtable
llvm: fix missing unwind info (wrong uwtable attribute value)
2022-09-26 23:05:39 +02:00
kcbanner
328f75c985 llvm: fix uwtable attribute value 2022-09-25 01:52:40 -04:00
Veikka Tuominen
fdf4c875ff llvm: avoid crash on duplicate asm input/output name 2022-09-24 14:43:03 +03:00
Andrew Kelley
99b954b9ce LLVM: remove purposeless const qualifiers
These const qualifiers on pointers to opaque types do not serve any
purpose. If anything they are misleading since the underlying pointers
very likely point to objects that are in fact mutated.

This commit does not change any behavior.
2022-09-21 13:27:23 -07:00
Andrew Kelley
37cdb5dbf9 Merge remote-tracking branch 'origin/master' into llvm15 2022-09-09 10:26:17 -07:00
Andrew Kelley
1b6fa1965a stage2: fix building for 32-bit targets 2022-09-08 20:52:49 -07:00
Veikka Tuominen
c7e45aebaf llvm: handle pointers in packed structs in more places
Closes #12776
2022-09-08 12:51:40 +03:00
Andrew Kelley
b7900de168 Merge remote-tracking branch 'origin/master' into llvm15 2022-09-06 19:45:02 -07:00
Veikka Tuominen
9ce841a0f0 stage2 llvm: implement aarch64 C ABI
... at least enough to pass all the current tests.
2022-09-04 18:46:56 +03:00
riChar
349cf54b32
llvm: fix the type parameter of GlobalAlias
Closes 12680
2022-09-04 18:44:45 +03:00
Veikka Tuominen
0f61d1f0df stage2 llvm: improve handling of i128 on Windows C ABI 2022-09-03 03:42:42 +03:00
Veikka Tuominen
b83c037f9f Sema: only ABI sized packed structs are extern compatible 2022-09-03 01:04:46 +03:00
Veikka Tuominen
7a8d9af4a9 stage2 llvm: correct handling of zero-bit types in unionFieldPtr
Pointers to zero-bit types are not zero-bit types so the function should
return something.
Closes #12716
2022-09-02 17:57:10 +03:00
Veikka Tuominen
4462d08224 stage2 llvm: fix passing packed structs to callconv(.C) functions
Closes #12704
2022-09-02 17:57:10 +03:00
Andrew Kelley
fb81ba8762 LLVM: fix extern functions missing attributes
Extern functions were missing attributes such as "readonly" on
non-optional pointers, and "byval" which is required to match C ABI.

Follow-up from bf28765a975355c27558eaa86cf00ccb29b663a7.

closes #12683
2022-08-30 14:45:03 -07:00
Andrew Kelley
1e21876de2 Merge remote-tracking branch 'origin/master' into llvm15 2022-08-30 13:02:43 -07:00
Andrew Kelley
7377dce368 avoid exposing supportsTailCall in the standard library
This is problematic because in practice it depends on whether the
compiler backend supports it too, as evidenced by the TODO comment about
LLVM not supporting some architectures that in fact do support tail
calls.

Instead this logic is organized strategically in src/target.zig, part of
the internal compiler source code, and the behavior tests in question
duplicate some logic for deciding whether to proceed with the test.

The proper place to expose this flag is in `@import("builtin")` - the
generated source file - so that third party compilers can advertise
whether they support tail calls.
2022-08-30 12:50:15 -07:00
Veikka Tuominen
c558de6655 stage2 llvm: use tag value instead of field index in airUnionInit
Closes #12656
2022-08-30 12:22:07 -07:00
Veikka Tuominen
67a44211f7 Sema: improve handling of always_tail call modifier
Closes #4301
Closes #5692
Closes #6281
Closes #10786
Closes #11149
Closes #11776
2022-08-30 12:22:07 -07:00