23410 Commits

Author SHA1 Message Date
Robin Voetter
34b98ee372
spirv: start lowering non-function decls
Start to lower decls which are not functions. These generate
an OpVariable instruction by which they can be used later on.
2023-04-09 01:51:51 +02:00
Robin Voetter
f1229e0f00
spirv: convert bools on load/store
Bools have a different immediate representation and memory
representation - which means that they must be converted every time
a bool is loaded from or stored into memory.
2023-04-09 01:51:51 +02:00
Robin Voetter
caf8461af8
spirv: make locals generic pointers
Taking the address of a local variable should result in a generic
pointer - too much code breaks if we do not do this. We cannot
lower locals into the generic storage class directly though, so
instead, lower the variables into the Function storage class
implicitly, and convert the pointer to a generic pointer.

Also Correct OpInboundsAccessChain generation (we only need
the one index).
2023-04-09 01:51:51 +02:00
Robin Voetter
2a8e784989
spirv: introduce type/value representations
There are two main ways in which a value can be stored: "Direct", as it
will be operated on as an immediate value, and "indirect", as it is stored
in memory. Some types need a different representation here: Bools, for
example, are opaque in SPIR-V, and so these need to have a different
representation in memory. The bool operations are not easily interchangable
with integer operations, though, so they need to be OpTypeBool as
immediate value.
2023-04-09 01:51:51 +02:00
Robin Voetter
8a00ec162c
spirv: more fixes and improvements
- Formatting.
- Improve `decorate` helper function to generate a decoration for a result-id.
- Reorder some functions in a more logical way
2023-04-09 01:51:51 +02:00
Robin Voetter
700dee34d5
spirv: make IdResultType and IdRef weak aliases of IdResult
Previously they were strong aliases, but as these types are used quite
intermittendly it resulted in a lot of toRef() calls. Removing them
improves readability a bit.
2023-04-09 01:51:51 +02:00
Robin Voetter
0c2526b18e
spirv: some fixes and improvements
- Adds the Int8. Int16, Int64 and GenericPointer capabilities.
  TODO: This should integrate with the feature system.
- Default some struct fields of SPIR-V types so that we dont
  need to type them all the time.
- Store struct field name's in SPIR-V types, and generate the
  OpMemberName decoration if they are non-null.
- Also add the field names to the actual SPIR-V types.
- Generate OpName for functions.
2023-04-09 01:51:50 +02:00
Robin Voetter
e443b1bed7
spirv: switch_br lowering
Implements lowering switch statements in the SPIR-V backend.
2023-04-09 01:51:50 +02:00
Robin Voetter
205d928b24
spirv: left shift
Implements the AIR left_shift operation for the SPIR-V backend.
2023-04-09 01:51:50 +02:00
Robin Voetter
ea97966c9e
spirv: struct field ptr index, ptr elem ptr
Implements the ptr_elem_ptr and struct_field_ptr_index_* AIR instructions
for the SPIR-V backend.
2023-04-09 01:51:50 +02:00
Robin Voetter
8608d6e235
spirv: div, rem, intcast, some strange integer masking
Implements the div-family and intcast AIR instructions, and starts
implementing a mechanism for masking the value of 'strange' integers
before they are used in an operation that does not hold under modulo.
2023-04-09 01:51:50 +02:00
Robin Voetter
23e210c38f
spirv: (some) array and struct constants
Starts implementing constant lowering for some array and struct constants.
In particular, TODO are packed structs.
2023-04-09 01:51:50 +02:00
Robin Voetter
bca6f2901a
spirv: enum values, struct_field_val, ret_ptr, ret_load
Implements lowering for enum constants, as well as the struct_field_val,
ret_ptr, and ret_load AIR instructions.
2023-04-09 01:51:49 +02:00
Robin Voetter
6146abee1e
spirv: add_with_overflow
Implements lowering for the add_with_overflow AIR instructions. Also implements
a helper function, simpleStructType, to quickly generate a SPIR-V structure type
without having to do the whole allocation dance.
2023-04-09 01:51:49 +02:00
Robin Voetter
c23d668c79
spirv: slice operations
This commit adds support for SPIR-V code generation for the following AIR
instructions:
- slice_ptr
- slice_len
- slice_elem_ptr
- slice_elem_val
2023-04-09 01:51:49 +02:00
Robin Voetter
3c5ab4dd3d
spirv: add liveness checks
When a result of a pure instruction is not used, it also does not need to
be generated. The other backends already implement these checks, they were
ignored in SPIR-V up until now. New instructions added in the future should
have these be implemented from the start.
2023-04-09 01:51:49 +02:00
Robin Voetter
39016948f0
spirv: slice types
Implements type lowering for slices.
2023-04-09 01:51:49 +02:00
Robin Voetter
3f92eaceb6
spirv: array, structs, bitcast, call
Implements type lowering for arrays and structs, and implements instruction
lowering for bitcast and call. Bitcast currently naively maps to the OpBitcast
instruction - this is only valid for some primitive types, and should be
improved to work with composites.
2023-04-09 01:51:49 +02:00
Robin Voetter
dae8b4c11f
spirv: emit OpName for some primitive types
OpName instructions assign a debug name to a type. Some basic
types - bool, void, ints, and floats are given a debug name this way.
TODO is to extend this to the other types.
2023-04-09 01:51:49 +02:00
Robin Voetter
3eafe3033e
spirv: improve storage efficiency for integer and float types
In practice there are only a few variations of these types allowed, so it
kind-of makes sense to write them all out. Because the types are hashed this
does not actually save all that many bytes in the long run, though. Perhaps
some of these types should be pre-registered?
2023-04-09 01:51:48 +02:00
Robin Voetter
5826a8a064
spirv: make Type.Ref stronger
Making Type.Ref an unbounded enum rather than a simple integer
ensures that we don't accidently confuse this token for another type.
2023-04-09 01:51:48 +02:00
Robin Voetter
a60308f87c
spirv: enum type
This gives the spir-v backend the power to emit enum types. These
are simply lowered to their backing integer type.
2023-04-09 01:51:48 +02:00
Robin Voetter
df5577c28b
spirv: allow more calling conventions
This allows the Zig calling convention and makes way for a Kernel
calling convention in the future. Any future checks on calling
conventions should be placed in Sema.zig.
2023-04-09 01:51:48 +02:00
Robin Voetter
ba60d456b4
spirv: cannot build libc
SPIR-V cannot build libc, ssp, compiler-rt, etc at the time of this commit, so
prevent trying to build them.
2023-04-09 01:51:48 +02:00
Robin Voetter
12ff362654
spirv: make genericName match target name.
Changes the 'generic name' of the target to spirv, from spir-v.
2023-04-09 01:51:48 +02:00
Robin Voetter
c6fbe0d5d8
dont destroy old bin file on link openpath failure
This was causing some crashes.
2023-04-09 01:51:47 +02:00
Robin Voetter
6dc1fafe98
std: add generic target for spirv
This adds a general target for SPIR-V compilation. Previously there was not
any target machine defined for SPIR-V.

TODO is to reword the features for this target. We don't really need the full
list of capabilities in the features, we should only put a few features here
which we can actually use during code generation.
2023-04-09 01:51:47 +02:00
Robin Voetter
17de4a88e9
spirv: add Addresses capability for opencl
This capability is required to generate SPIR-V kernels with the Physical32
and Physical64 memory models, which we use in OpenCL kernels.
2023-04-09 01:51:47 +02:00
Andrew Kelley
c22a30ac99 zig cc: handle the -r flag
This makes -r treated the same as -c which is to output an object file.
Zig's ELF linker code already handles multiple object files into an
object file with the -r flag to LLD.

closes #11683
2023-04-08 15:48:27 -04:00
Andrew Kelley
aa45854ec3 zig.h: fix typo for zig_trap definition 2023-04-08 09:54:32 -07:00
David CARLIER
2e2d37917d std: add FreeBSD's procctl api. 2023-04-08 18:31:01 +03:00
Luuk de Gram
58bab660b5
Merge pull request #15202 from SuperAuguste/misc-wasm
Implement `@shuffle`, fix vector element accesses for WASM backend
2023-04-08 17:13:58 +02:00
Nameless
fde05b10b3 tls.Client: don't read if we don't need more data 2023-04-08 03:37:05 -04:00
Auguste Rame
09fda08618
Fix 32-bit compile errors 2023-04-07 23:04:24 -04:00
Auguste Rame
7225a15abe
Enable new tests 2023-04-07 20:55:04 -04:00
Auguste Rame
8ba3ab948a
Handle compile time case for vector element access using lane access 2023-04-07 20:52:04 -04:00
Auguste Rame
1e310d3350
Finish shuffle, fix arrayElemVal for vectors 2023-04-07 20:35:15 -04:00
Andrew Kelley
55a8b7e1fa
Merge pull request #15097 from zachcheu/add-wrap-flag
add linker -wrap flag
2023-04-07 19:58:55 -04:00
Auguste Rame
d5511b35a9
Make airShuffle work for unrolled 2023-04-07 19:07:48 -04:00
Luuk de Gram
4ebf483e0d
Merge pull request #14668 from Techatrix/wasm-floatops
wasm: implement float operations with compiler-rt
2023-04-07 18:22:41 +02:00
Andrew Kelley
48f98494fd
Merge pull request #15195 from mlugg/fix/liveness-loop-defer-deaths
Liveness: defer deaths of externally-scoped instructions in loop bodies
2023-04-07 11:12:44 -04:00
Andrew Kelley
b086b7da9e zig cc: complete the -wrap flag implementation
* use a set instead of a list
* use of this flag currently requires LLD
* add documentation
* make it only a zig cc compatibility flag for now because I personally
  think this is an anti-feature.
2023-04-07 07:54:47 -07:00
Zach Cheung
1fdea551b2 add linker -wrap flag 2023-04-07 09:09:38 -04:00
mateusz
0866396308
std.json: allow returning custom errors from custom stringify 2023-04-07 15:01:09 +03:00
Auguste Rame
dac62424f9 Make self-hosted wasm @returnAddress return 0 2023-04-07 14:59:22 +03: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
13aa7871b2
Merge pull request #15101 from motiejus/glibc_compat
glibc: add backwards compatibility for some symbols
2023-04-06 17:15:58 -04:00
Andrew Kelley
9f957184a1 Merge remote-tracking branch 'origin/master' into llvm16 2023-04-06 13:58:54 -07:00
Andrew Kelley
271f24f047 CI: disable reproducibility check on x86_64-macos 2023-04-06 13:58:25 -07:00