Commit Graph
100 Commits
Author SHA1 Message Date
Robin Voetter dc6ffc28b5 Merge pull request #23815 from alichraghi/master
spirv: unroll all vector operations
2025-05-25 12:36:53 +02:00
Robin Voetter cc381d56a6 Merge pull request #23654 from alichraghi/continue
Compilation: don't build compiler_rt or ubsan_rt for amdgcn and ptx
2025-04-30 20:46:12 +02:00
Robin Voetter aa8aa66253 Merge pull request #23297 from igaryhe/dan/more-spirv-optype
spirv: Assemble OpTypeRuntimeArray.
2025-03-20 12:14:05 +01:00
Robin Voetter 5105c3c7fa Merge pull request #23158 from alichraghi/ali_spirv
spirv: miscellaneous stuff #2
2025-03-18 22:31:57 +01:00
Robin Voetter d856763aca Merge pull request #22937 from alichraghi/ali_spv
spirv: make test suite working again
2025-02-25 20:27:37 +01:00
Robin Voetter fe5a78691f spirv: get rid of function_types cache
This deep hash map doesn't work
2025-02-24 20:58:13 +01:00
Robin Voetter 4720a79477 Merge pull request #22889 from alichraghi/ali_spv
spirv: miscellaneous stuff
2025-02-18 21:14:02 +01:00
Robin Voetter 62f4a6b4d8 Merge pull request #21937 from Snektron/spirv-vulkan-ptrs
spirv: miscellaneous vulkan + zig stuff
2024-11-09 21:50:33 +01:00
Robin Voetter 9cd7b8359c spirv: enable variable pointers for now
This seems to be required for ptr_elem_ptr with storage buffers. Note that
this does not imply that the pointer can be regarded as physical too.

Some variants of ptr_elem_ptr will need to be forbidden
2024-11-09 01:53:13 +01:00
Robin Voetter efb7539cb6 spirv: dont emit forward pointer for annotation instructions 2024-11-09 01:53:13 +01:00
Robin Voetter 89bd987f1c spirv: emit ArrayStride for many-item pointers 2024-11-08 20:43:57 +01:00
Robin Voetter b16252b17e spirv: make all vulkan structs Block for now 2024-11-08 20:43:57 +01:00
Robin Voetter d35dfc5a3f add storage_buffer address space 2024-11-08 20:43:57 +01:00
Robin Voetter 688d7055e3 spirv: assembler hacky constant placeholders 2024-11-08 20:43:55 +01:00
Robin Voetter b5301558ae spirv: make default generic address space for vulkan Function
We are not using Private variables. This needs to be cleaned up a bit
more, this will happen with the general address space improvements.
2024-11-08 20:38:23 +01:00
Robin Voetter 7682ced08e spirv: track global OpVariables properly in assembler
Also cleans up the assembler a bit in general.
2024-11-08 20:38:22 +01:00
Robin Voetter 4fbc100959 spirv: properly resolve type inputs in assembly
For now the frontend still allows type inputs in assembly. We
might as well resolve them properly in the SPIR-V backend.
2024-11-08 20:38:21 +01:00
Robin Voetter 08ad7afc1e spirv: forbid pointer arithmetic 2024-11-08 20:38:20 +01:00
Robin Voetter ba5f57616f Merge pull request #21861 from alichraghi/master
spirv: push constants and small fixes
2024-11-01 03:44:37 +01:00
Robin Voetter 3450809e3d Merge pull request #21826 from Snektron/spirv-vulkan
spirv: vulkan setup
2024-10-29 19:58:51 +01:00
Robin Voetter ae57f6fd07 dwarf: flush wip_nav after emitting anyerror type info
This caused a missing reference for u16 to not be emitted. Triggered
after removing something from start.zig which transitively added u16
to the module.
2024-10-28 20:39:37 +01:00
Robin Voetter 6d8ee89721 fix compile error tests with unstable error sets
The print order of error sets depends on the order that the compiler
adds names to its internal state. These names can be anything, and
do not necessarily need to be from the same error set or be errors
at all. When the last remaining reference to builtin.cpu.arch was
removed in start.zig in 9b42bc1ce5, this order changed. Likely there
is something that has the name 'C' that is referenced somewhere
recursively from builtin.cpu.arch.

This all causes these few tests to fail, and hence the expected
order is simply updated now. Perhaps there is a better way to
add this.
2024-10-27 18:02:12 +01:00
Robin Voetter 49a067ccfe spirv: forbid merging logical pointers
Under some architecture/operating system combinations it is forbidden
to return a pointer from a merge, as these pointers must point to a
location at compile time. This adds a check for those cases when
returning a pointer from a block merge.
2024-10-27 16:31:45 +01:00
Robin Voetter 39013619b9 spirv: generate test entry points for vulkan 2024-10-27 15:19:57 +01:00
Robin Voetter 7c69231367 spirv: use PhysicalStorageBuffer64 for global pointers under vk
We can use real pointers with this storage class!!
2024-10-27 15:19:56 +01:00
Robin Voetter 6de456c179 spirv: fix up calling conventions for vulkan
* Fragment and Vertex CCs are only valid for SPIR-V when
  running under Vulkan.
* Emit GLCompute instead of Kernel for SPIR-V kernels.
2024-10-27 15:19:55 +01:00
Robin Voetter 9b42bc1ce5 spirv: start.zig support for vulkan
* Use builtin.zig_backend instead of builtin.cpu.arch, the latter
  does not yet compile under VK.
* Don't call regular _start for either opencl or vulkan. We might
  even want to disable these completely.
2024-10-27 14:20:52 +01:00
Robin Voetter e2e79960d2 Merge pull request #21688 from Snektron/spirv-fix
spirv: fix some bitrot
2024-10-13 22:33:03 +02:00
Robin Voetter 86b88ea7da spirv: skip range switch tests
This is not yet implemented
2024-10-13 01:58:11 +02:00
Robin Voetter c1132edd53 spirv: don't generate OpUnreachable after noreturn call
It seems that these are now automatically added to AIR in Sema.
2024-10-13 01:57:35 +02:00
Robin Voetter 973f846251 spirv: implement repeat and dbg_arg_inline 2024-10-13 01:57:06 +02:00
Robin Voetter 3cd19b8884 spirv: don't try to lower types which have no runtime bits 2024-10-13 01:56:33 +02:00
Robin Voetter 80999391d9 re-enable emit_asm_and_bin and emit_llvm_no_bin tests
These were fixed during the last few commits too. The emit_llvm_no_bin test
is renamed from the issue_12588 test.

Closes #17484
2024-08-19 19:09:13 +02:00
Robin Voetter 294ca6563e add standalone test for only dependending on the emitted assembly and not the bin 2024-08-19 19:09:13 +02:00
Robin Voetter b4343074d2 replace Compilation.Emit with std.Build.Cache.Path
This type is exactly the same as std.Build.Cache.Path, except for
one function which is not used anymore. Therefore we can replace
it without consequences.
2024-08-19 19:09:12 +02:00
Robin Voetter 43f73af359 fix various issues related to Path handling in the compiler and std
A compilation build step for which the binary is not required could not
be compiled previously. There were 2 issues that caused this:

- The compiler communicated only the results of the emitted binary and
  did not properly communicate the result if the binary was not emitted.

  This is fixed by communicating the final hash of the artifact path (the
  hash of the corresponding /o/<hash> directory) and communicating this
  instead of the entire path. This changes the zig build --listen protocol
  to communicate hashes instead of paths, and emit_bin_path is accordingly
  renamed to emit_digest.

- There was an error related to the default llvm object path when
  CacheUse.Whole was selected. I'm not really sure why this didn't manifest
  when the binary is also emitted.

  This was fixed by improving the path handling related to flush() and
  emitLlvmObject().

In general, this commit also improves some of the path handling throughout
the compiler and standard library.
2024-08-19 19:09:11 +02:00
Robin Voetter 1018cdc0a8 Merge pull request #21030 from Snektron/nv-gpu-builtins
nvptx: add implementations for GPU builtins
2024-08-14 04:14:34 +02:00
Robin Voetter bcfc7cf13c nvptx: add implementations for GPU builtins 2024-08-13 20:07:23 +02:00
Robin Voetter 6d7bbab740 Merge pull request #20696 from sobolevn/typos-fix
Fix typos in code comments in `src/`
2024-07-20 22:28:42 +02:00
Robin Voetter 8f27a43701 Merge pull request #20309 from Snektron/spirv-gpu-builtins
spirv: add support for GPU builtins
2024-06-16 08:42:35 +02:00
Robin Voetter 50a771a11e spirv: add support for workItemId, workGroupId, workGroupSize 2024-06-16 01:00:13 +02:00
Robin Voetter d9bd34fd05 Merge pull request #20247 from Snektron/spirv-vectors-v3
spirv: vectors v3
2024-06-11 08:21:04 +02:00
Robin Voetter a567f3871e spirv: improve shuffle codegen 2024-06-10 20:32:50 +02:00
Robin Voetter a3b1ba82f5 spirv: new vectorization helper
The old vectorization helper (WipElementWise) was clunky and a bit
annoying to use, and it wasn't really flexible enough.

This introduces a new vectorization helper, which uses Temporary and
Operation types to deduce a Vectorization to perform the operation
in a reasonably efficient manner. It removes the outer loop
required by WipElementWise so that implementations of AIR instructions
are cleaner. This helps with sanity when we start to introduce support
for composite integers.

airShift, convertToDirect, convertToIndirect, and normalize are initially
implemented using this new method.
2024-06-10 20:32:49 +02:00
Robin Voetter 4e7159ae1d spirv: remove OpCompositeConstruct workarounds
Now that we use POCL to test, we no longer need this ✨
2024-06-10 20:32:43 +02:00
Robin Voetter 4bd9d9b7e0 spirv: change direct vector child repr to direct
Previously the child type of a vector was always in indirect representation.
Concretely, this meant that vectors of bools are represented by vectors
of u8.

This was undesirable because it introduced a difference between vectorizable
operations with a scalar bool and a vector of bool. This commit changes the
representation to be the same for vectors and scalars everywhere.

Some issues arised with constructing vectors: it seems the previous temporary-
and-pointer approach does not work properly with vectors of bool. To work around
this, simply use OpCompositeConstruct. This is the proper instruction for this,
but it was previously not used because of a now-solved limitation in the
SPIRV-LLVM-Translator. It was not yet applied to Zig because the Intel OpenCL
CPU runtime does not have a recent enough version of the translator yet, but
to solve that we just switch to testing with POCL instead.
2024-06-10 20:32:43 +02:00
Robin Voetter b9d738a5cf spirv: disable tests that fail on pocl
Besides the Intel OpenCL CPU runtime, we can now run the
behavior tests using the Portable Computing Language. This
implementation is open-source, so it will be easier for us
to patch in updated versions of spirv-llvm-translator that
have bug fixes etc.
2024-06-10 20:32:34 +02:00
Robin Voetter 44443b833b build: inherit setExecCmd from test compile steps when creating run steps
This should fix #17756
2024-06-09 01:55:50 +02:00
Robin Voetter fba6b7e4c2 spirv: fix error code encoding 2024-06-09 01:55:49 +02:00
Robin Voetter ac16545895 spirv: enable passing tests 2024-04-06 13:52:48 +02:00
Robin Voetter cbf2ee72e3 spirv: fix some recursive pointers edge cases in dedup pass 2024-04-06 13:37:41 +02:00
Robin Voetter 125d3324d9 spirv: add link progression 2024-04-06 13:37:41 +02:00
Robin Voetter 3e388faecd spirv: yeet cache 2024-04-06 13:37:40 +02:00
Robin Voetter ef638502d4 spirv: remove cache usage from assembler 2024-04-06 13:37:40 +02:00
Robin Voetter 97a67762ba spirv: remove cache usage for types 2024-04-06 13:37:39 +02:00
Robin Voetter 188922a544 spirv: remove cache usage for constants 2024-04-06 13:37:39 +02:00
Robin Voetter 42c7e752e1 spirv: id range helper
This allows us to more sanely allocate a continuous
range of result-ids, and avoids a bunch of nasty
casting code in a few places. Its currently not used
very often, but will be useful in the future.
2024-04-06 13:37:37 +02:00
Robin Voetter 3942083806 Merge pull request #18984 from alichraghi/vector
spirv: implement `@divFloor`, `@floor`, `@mod` and `@mulWithOverflow`
2024-04-06 13:37:25 +02:00
Robin Voetter df1f8b0ae6 Merge pull request #19539 from alichraghi/spirv
spirv: make behavior tests passing
2024-04-05 23:22:34 +02:00
Robin Voetter d2be725e4b Merge pull request #19490 from Snektron/spirv-dedup
spirv: deduplication pass
2024-04-01 09:51:04 +02:00
Robin Voetter 27b91288dc spirv: disable failing tests 2024-03-30 19:47:56 +01:00
Robin Voetter 12350f53bf spirv: clz, ctz for opencl
This instruction seems common in compiler_rt.
2024-03-30 19:47:55 +01:00
Robin Voetter f5ab3c93c9 spirv: handle annotations in deduplication pass 2024-03-30 19:47:55 +01:00
Robin Voetter b4960394ef spirv: avoid copying operands in dedup pass 2024-03-30 19:47:52 +01:00
Robin Voetter 393a805741 spirv: deduplicate prototype 2024-03-30 10:16:18 +01:00
Robin Voetter 7057bffc14 Merge pull request #19337 from Snektron/spirv-globals
spirv: rework generic global
2024-03-19 09:34:59 +01:00
Robin Voetter 2f9e37ade0 spirv: enable passing tests 2024-03-18 19:13:51 +01:00
Robin Voetter 4020b91f21 spirv: skip test that miscompiles on Intel 2024-03-18 19:13:51 +01:00
Robin Voetter 335ff5a5f4 spirv: fix optional comparison 2024-03-18 19:13:50 +01:00
Robin Voetter 8ed134243a spirv: unused instruction pruning linker pass 2024-03-18 19:13:50 +01:00
Robin Voetter 9b18125562 spirv: make generic globals invocation-local 2024-03-18 19:13:50 +01:00
Robin Voetter 20d7bb68ac spirv: add zig-specific ext inst
This may be removed again in the future...
2024-03-18 19:13:49 +01:00
Robin Voetter e566158acf spirv: make IdResult an enum 2024-03-18 19:13:49 +01:00
Robin Voetter 9b058117f0 spirv: update assembler with new spec 2024-03-18 19:13:48 +01:00
Robin Voetter 028f532dc0 spirv: update spec to SPIRV-Headers/8b246ff
We need this "unstable" version to get the Zig identifiers.
2024-03-18 19:13:47 +01:00
Robin Voetter 3d5721da23 spirv: update spec generator
For module parsing and assembling, we will also need to know
all of the SPIR-V extensions and their instructions. This commit
updates the generator to generate those. Because there are
multiple instruction sets that each have a separate list of Opcodes,
no separate enum is generated for these opcodes. Additionally, the
previous mechanism for runtime instruction information, `Opcode`'s
`fn operands()`, has been removed in favor for
`InstructionSet.core.instructions()`.

Any mapping from operand to instruction is to be done at runtime.
Using a runtime populated hashmap should also be more efficient
than the previous mechanism using `stringToEnum`.
2024-03-18 19:13:46 +01:00
Robin Voetter 3bffa58012 Revert "spirv: merge construct(Struct/Vector/Array) into constructComposite"
This reverts commit eb2d61d02e.
2024-03-17 14:17:26 +01:00
Robin Voetter dd4d320eb9 Merge pull request #18948 from alichraghi/vector
spirv: use extended instructions whenever possible
2024-02-17 14:01:07 +01:00
Robin Voetter 7634a115c5 Merge pull request #18580 from Snektron/spirv-more-vectors
spirv: more vector operations
2024-02-05 09:24:49 +01:00
Robin Voetter 2511106150 spirv: air vector_store_element 2024-02-04 19:09:34 +01:00
Robin Voetter 9fbba0e01a spirv: update tests 2024-02-04 19:09:33 +01:00
Robin Voetter 1d548aa2aa spirv: air splat 2024-02-04 19:09:33 +01:00
Robin Voetter 76d5696434 spirv: air abs 2024-02-04 19:09:32 +01:00
Robin Voetter 631d1b63a8 spirv: fix shuffle properly 2024-02-04 19:09:32 +01:00
Robin Voetter 9641d2ebdb spirv: vectorize max, min 2024-02-04 19:09:31 +01:00
Robin Voetter 9f0227a326 spirv: vectorize int_cast, trunc 2024-02-04 19:09:31 +01:00
Robin Voetter 408c117246 spirv: air is_(non_)null_ptr, optional_payload_ptr 2024-02-04 19:09:30 +01:00
Robin Voetter 7dfd403da1 spirv: air mul_add 2024-02-04 19:09:30 +01:00
Robin Voetter 345d6e280d spirv: air int_from_bool 2024-02-04 19:09:29 +01:00
Robin Voetter 77ef78a0ef spirv: clean up arithmeticTypeInfo a bit
- No longer returns an error
- Returns more useful vector info
2024-02-04 19:09:29 +01:00
Robin Voetter 54ec936549 spirv: wrap strange its before instead of after operation
Wrapping strange integers before an operation was initially
done as an attempt to minimize the amount of normalizations
required: This way, there would not be a normalization
necessary between two modular operations. This was a
premature optimization, since the resulting logic is more
complicated than naive way of wrapping the result after
the operation.

This commit updates handling of strange integers to do
wrapping after each operation. It also seems slightly
more efficient in terms of size of generated code, as
it reduces the size of the behavior tests binary by
about 1%.
2024-02-04 19:09:28 +01:00
Robin Voetter b67d983abd spirv: vectorize add/sub overflow 2024-02-04 19:09:27 +01:00
Robin Voetter 761594e226 spirv: reduce, reduce_optimized 2024-02-04 19:09:27 +01:00
Robin Voetter 2f815853dc spirv: shlWithOverflow 2024-02-04 19:09:26 +01:00
Robin Voetter 15cf5f88c1 spirv: vectors for air not 2024-02-04 19:09:25 +01:00
Robin Voetter 403c6262bb spirv: use new vector stuff for arithOp and shift 2024-02-04 19:09:18 +01:00
Robin Voetter cb9e20da00 spirv: element-wise operation helper 2024-02-04 19:09:00 +01:00
Robin Voetter 747f4ae3f5 spirv: sh[rl](_exact)? 2024-02-04 19:08:59 +01:00
Robin Voetter 3ef5b80d2c std: use simple eqlBytes for spirv
The SPIR-V backend doesn't support the advanced
eqlBytes yet, and when it does, it likely that it
will be detrimental.
2024-02-04 19:08:57 +01:00
Robin Voetter 608b5d06ea Merge pull request #18097 from Snektron/spirv-structured-codegen
spirv: structured codegen
2023-11-24 23:01:32 +01:00