143 Commits

Author SHA1 Message Date
Robin Voetter
3c4cc1eedb
spirv: eliminate remaining uses of emitConstant 2023-05-30 19:43:37 +02:00
Robin Voetter
0552a8b11f
spirv: translate remaining types 2023-05-30 19:43:37 +02:00
Robin Voetter
fcb422585c
spirv: translate remaining types 2023-05-30 19:43:37 +02:00
Robin Voetter
05f1392d8b
spirv: translate vectors to cache key 2023-05-30 19:43:37 +02:00
Robin Voetter
f13a6ee19e
spirv: cache pointers 2023-05-30 19:43:36 +02:00
Robin Voetter
e05ace7673
spirv: cache function prototypes 2023-05-30 19:43:36 +02:00
Robin Voetter
8c72ad5320
spirv: cache for ints 2023-05-30 19:43:36 +02:00
Robin Voetter
b2a984cda6
spirv: basic setup for using new type constant cache 2023-05-30 19:43:36 +02:00
Veikka Tuominen
ca16f1e8a7 std.Target adjustments
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi
* double isn't always 8 bits
* AVR uses 1-byte alignment for everything in GCC
2023-05-26 21:42:19 -07:00
Andrew Kelley
7621e56938
Merge pull request #15753 from Snektron/spirv-more-tests
spirv: make more tests pass
2023-05-20 13:54:01 -07:00
Robin Voetter
c92cc5798f
spirv: make constant handle float, errorset, errorunion
This is in preparation of removing indirect lowering again. Also
modifies constant() to accept a repr so that both direct as well
as indirect representations can be generated. Indirect is not yet
used, but will be used for globals.
2023-05-20 18:02:30 +02:00
Robin Voetter
d7ddaf64a2 spirv: don't generate union tag type if it doesnt exist
Previously the tag type was generated even if it was nonexistant,
triggering an assertion that an integer type should never have
zero bits. Now its only generated when the tag type is actually emitted.
2023-05-20 08:48:38 -07:00
Robin Voetter
65157d30ab
spirv: ptr_elem_val
Implements the ptr_elem_val air tag. Implementation is unified
with ptr_elem_ptr.
2023-05-20 17:30:23 +02:00
Robin Voetter
77b8bf2b82
spirv: ptr_sub
Implments the ptr_sub air tag. The code is unified with that of ptr_add.
2023-05-20 17:30:22 +02:00
Robin Voetter
2f28713bd7
spirv: pointer bitcasting 2023-05-20 17:30:22 +02:00
Robin Voetter
4203d099be
spirv: lower integer pointer constants 2023-05-20 17:30:22 +02:00
Robin Voetter
64f99f36a6
spirv: ptr_add
Implements the ptr_add air tag for spirv.

The implementation for slices is probably wrong, but there seems to be no test for this...
2023-05-20 17:30:22 +02:00
Robin Voetter
3c14438a93
spirv: use extractField more
reduce some code duplication
2023-05-20 17:30:21 +02:00
Robin Voetter
6c05557072
spirv: fix some (Ptr)AccessChain uses
The first dereference of PtrAccessChain returns a pointer of the same type
as the base pointer, in contrast to AccessChain, where the first dereference
returns a pointer of the dereferenced type of the base pointer.
2023-05-20 17:30:21 +02:00
Robin Voetter
0ba0d8fecb
spirv: dont use OpIAddCarry
This instruction is not really working well in the LLVM SPIRV translator,
as it is not implemented.

This commit also intruces the constructStruct helper function to initialize
structs at runtime. This is ALSO buggy in the translator, and we must work
around OpCompositeConstruct not working when some of the constituents are
runtime-known only.

Some other improvements are made:
- improved variable() so that it is more useful and no longer requires the
  address space. It always puts values in the Function address space,
  and returns a pointer to the Generic address space
- adds a boolToInt utility function
2023-05-20 17:30:21 +02:00
Robin Voetter
7d519b3383
spirv: use intInfo instead of arithmeticTypeInfo in airIntCast
This ensures that we can also cast enums and error sets here. In the future
this function will need to be changed to support composite and strange
integers, but that is fine.
2023-05-20 17:30:21 +02:00
Robin Voetter
6e3770e970
spirv: implement pointer comparison in for air cmp
It turns out that the Khronos LLVM SPIRV translator does not support OpPtrEqual.
Therefore, this instruction is emitted using a series of conversions.

This commit breaks intToEnum, because enum was removed from the arithmetic type
info. The enum should be converted to an int before this function is called.
2023-05-20 17:30:21 +02:00
Ali Chraghi
fedc9a19e7 spirv: lower get_union_tag 2023-05-20 18:43:26 +03:30
Ali Chraghi
6fca3f8b72 spirv: lower ptrtoint & ignore dbg_inline instructions 2023-05-15 22:04:42 +03:30
Ali Chraghi
f8de4db873 spirv: implement arithmeticTypeInfo for Enum (@intToEnum) 2023-05-15 14:22:40 +03:30
Ali Chraghi
9c550721e4 spirv: lower float_to_int and int_to_float 2023-05-15 03:04:17 +03:30
Ali Chraghi
d61dc3a5a2
spirv: lower store_safe, trunc and trap 2023-05-11 20:31:52 +02:00
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
mlugg
6f09a7041e
Begin integrating new liveness analysis into remaining backends 2023-04-20 20:49:34 +01:00
Robin Voetter
979b410258
spirv: Do not generate the Alignment attribute on pointers for now
It seems that some implementations may have problems with these right now,
like Intel and Rusticl. In theory, these attributes should be superficial
on the pointer type, as alignment guarantees are also added via the
alignment option of the OpLoad and OpStore instructions. Therefore, get rid
of them for now.
2023-04-09 01:51:55 +02:00
Robin Voetter
45b5f46770
spirv: allow global, constant address spaces
These should actually just work fine in SPIR-V. They are mapped to CrossWorkgroup
and UniformConstant respectively.
2023-04-09 01:51:54 +02:00
Robin Voetter
e389f524c9
spirv: export functions with .Kernel callconv as entry point
Exported functions which have the .Kernel calling convention are now exported
as entry point. This also works with @export.
2023-04-09 01:51:54 +02:00
Robin Voetter
3f2025f59e
spirv: emit interface variables for entry points
Also actually implement generating the OpEntryPoint instructions.
2023-04-09 01:51:54 +02:00
Robin Voetter
405f7298ac
spirv: add decl dependencies for functions also
Entry points need to be attributed with a complete list of
global variables that they use. To that end, the global dependencies
mechanism is extended to also allow functions - when flushing the
module, the list of dependencies is examined to generate this
list of global variable result-ids.
2023-04-09 01:51:53 +02:00
Robin Voetter
efe7fae6af
spirv: temporarily emit test kernels
SPIR-V cannot represent function pointers without extensions
that no vendor implements. For the time being, generate a test
kernel for each error, so that we can at least run SOME tests.

In the future we may be able to emulate function pointers in some
way, but that is not today.
2023-04-09 01:51:53 +02:00
Robin Voetter
719d47d823
spirv: implement error set and error unions
Implements lowering types and constants for error sets and error unions.
2023-04-09 01:51:53 +02:00
Robin Voetter
8bbfbfc956
spirv: improve linking globals
SPIR-V globals must be emitted in order, so that any
declaration precedes usage. Zig, however, generates globals in
random order. To this end we keep for each global a list of
dependencies and perform a topological sort when flushing the
module.
2023-04-09 01:51:53 +02:00
Robin Voetter
80b8435569
spirv: overhaul constant lowering
Lowering constants is currently not really compatible with unions. In
this commit, constant lowering is drastically overhauled: instead of
playing nice and generating SPIR-V constant representations for everything
directly, we're just going to treat globals as an untyped bag of bytes (
or rather, SPIR-V 32-bit words), which we cast to the desired type at
usage. This is similar to how Rust generates constants in its LLVm backend.
2023-04-09 01:51:53 +02:00
Robin Voetter
764f19034d
spirv: union types/constants
Implements lowering union types and constants in the SPIR-V backend.
2023-04-09 01:51:53 +02:00
Robin Voetter
75abe3b43b
spirv: optional constants
Implements lowering optional constants in the SPIR-V backend.
2023-04-09 01:51:53 +02:00
Robin Voetter
0c53fea42c
spirv: improve genConstant usage
This little wrapper function allocates a result-id for us,
so that we don't have to do that.
2023-04-09 01:51:52 +02:00
Robin Voetter
12a3a8b100
spirv: slice constants
Implements lowering slice constants in the SPIR-V backend
2023-04-09 01:51:52 +02:00