63 Commits

Author SHA1 Message Date
Arseniy Obolenskiy
d8f71b1638
[SPIR-V] Add support for SPV_INTEL_masked_gather_scatter extension (#185418)
Fixes the first bullet in #184638 

Corresponding patch to add support for vector operands in
OpConvertPtrToU/OpConvertUToPtr operations in spirv-val:
https://github.com/KhronosGroup/SPIRV-Tools/pull/6575

SPIR-V extension reference used:
278044a51f/extensions/INTEL/SPV_INTEL_masked_gather_scatter.asciidoc
2026-03-11 13:14:36 +01:00
Nick Sarnie
aef962708f
Reapply "[SPIRV][NFCI] Use unordered data structures for SPIR-V extensions (#184162)
Reapply https://github.com/llvm/llvm-project/pull/183567 with minor
changes.

Problem causing the revert was we couldn't use the enum in `DenseMap`
directly because of some `TableGen` limitations so I casted made the map
use the underlying type, but that caused some UB, so I
[fixed](https://github.com/llvm/llvm-project/pull/183769) the `TableGen`
limitation so now it just works.
2026-03-03 15:51:55 +00:00
Nick Sarnie
729602e810
Revert "[SPIRV][NFCI] Use unordered data structures for SPIR-V extensions" (#183774)
Reverts llvm/llvm-project#183567

UBSan failure.
2026-02-27 17:18:55 +00:00
Nick Sarnie
d8956d7796
[SPIRV][NFCI] Use unordered data structures for SPIR-V extensions (#183567)
Review follow-up from https://github.com/llvm/llvm-project/pull/183325
No reason for these data structures to be ordered.

Minor annoyance when trying to use `DenseMap` because of the C++ code
for enums generated by TableGen, but not too bad.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
2026-02-27 15:51:57 +00:00
Nick Sarnie
78689630b3
[SPIRV] Fix disabling of default extensions (#183325)
If you pass `-ExtName` to the `--spirv-ext` command line option. that
should disable the extension. However some vendors have some extensions
enabled by default when using a triple with that vendor, and disabling
an extension with the option did not effect the default extensions.

This PR makes it so disabling an extension with the `--spirv-ext` option
actually disables the extension.

The problem was we only considered the disabled extension when parsing
the arguments for `--spirv-ext`, but the default extensions are added
separately, so we need to store the disabled extensions and factor them
in when computing the final extension set to use.

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
2026-02-26 15:34:16 +00:00
Juan Manuel Martinez Caamaño
9d55f14098
[SPIRV][AMD] Reenable SPV_KHR_float_control2 for AMD flavored SPIRV (#182873)
`SPV_KHR_float_controls2` is enabled in the translator after
https://github.com/khronosgroup/spirv-llvm-translator/pull/3475.

This extension was disabled since we were not able to translate it back.

This patch reverts #169659.
2026-02-25 12:59:11 +00:00
Dmitry Sidorov
fcc4231ac5
[SPIR-V] Add SPV_INTEL_unstructured_loop_controls extension (#178799)
For compute we don't run structurizer hence we won't be able to preserve
loop metadata via LoopMerge instruction. So
SPV_INTEL_unstructured_loop_controls is the only way we can preserve the
info in unstructured control flow.
2026-02-02 15:06:18 +01:00
Viktoria Maximova
8f8dfbf8c9
[SPIR-V] Implement SPV_KHR_fma extension (#173057)
The extension adds support for the `OpFmaKHR` instruction, which
provides a native SPIR-V instruction for fused multiply-add operations
as an alternative to using OpenCL.std::Fma extended instruction.

Translate both LLVM fma intrinsics as well as OCL builtins to `OpFmaKHR`
if the extension is available.

Specification:

https://github.khronos.org/SPIRV-Registry/extensions/KHR/SPV_KHR_fma.html
2026-01-29 17:39:57 -08:00
Michal Paszkowski
a679a25ceb
Revert " [SPIRV] Addition of extension SPV_KHR_non_semantic_info and SPV_KHR_relaxed_extended_instruction" (#177093)
Reverts llvm/llvm-project#169643 due to build issues
2026-01-20 21:41:31 -08:00
Aadesh Premkumar
287be74a02
[SPIRV] Addition of extension SPV_KHR_non_semantic_info and SPV_KHR_relaxed_extended_instruction (#169643)
--Added support for the extension SPV_KHR_non_semantic_info
--Added support for the extension SPV_KHR_relaxed_extended_instruction 
--Added instructions from the documentation of the extension. 
--Added supporting tests for the same.

Same as #165302

---------

Co-authored-by: Michal Paszkowski <michal@michalpaszkowski.com>
2026-01-20 21:36:01 -08:00
Subash B
075e4672a6
[SPIRV] Added Support for the SPV_ALTERA_arbitrary_precision_floating_point Extension (#160054)
Added support for the SPV_ALTERA_arbitrary_precision_floating_point
extension, enabling all the arbitrary precision floating-point
operations with instruction definitions and test files.
2026-01-14 00:37:22 -08:00
Ramkumar Ramachandra
d69335bac9
[LLVM] Clean up code using [not_]equal_to (NFC) (#175824)
Use llvm::[not_]equal_to landed in d2a521750 ([ADT] Introduce
bind_{front,back}, [not_]equal_to, #175056) across LLVM for cleaner
code.
2026-01-13 21:19:39 +00:00
Aadesh Premkumar
2c26d56045
[SPIRV] Support for the extension SPV_EXT_image_raw10_raw12 (#160032)
Added support for SPV_EXT_image_raw10_raw12 extension.
2025-12-15 23:57:36 -08:00
Alex Voicu
0fff58a50f
[NFC][SPIRV] Re-work extension parsing (#171826)
This changes the extension parsing mechanism underpinning `--spirv-ext`
to be more explicit about what it is doing and not rely on a sort. More
specifically, we partition extensions into enabled (prefixed with `+`)
and others, and then individually handle the resulting ranges.
2025-12-15 14:40:14 +00:00
Alex Voicu
ef47462ce9
[SPIRV] Start adding support for int128 (#170798)
LLVM has pretty thorough support for `int128`, and it has started seeing
some use. Even thouth we already have support for the
`SPV_ALTERA_arbitrary_precision_integers` extension, the BE was oddly
capping integer width to 64-bits. This patch adds partial support for
lowering 128-bit integers to `OpTypeInt 128`. Some work remains to be
done around legalisation support and validating constant uses (e.g.
cases that get lowered to `OpSpecConstantOp`).
2025-12-09 17:11:28 +00:00
Alex Voicu
93d64a5c4d
[SPIRV] Add <2 x half> and <4 x half> atomics via SPV_NV_shader_atomic_fp16_vector (#170213)
This adds support for the `SPV_NV_shader_atomic_fp16_vector` extension,
and then uses it to enable lowering of atomic add, sub, min and max on 2
and 4 component vectors of FP16, which are rather common options in ML
workloads. Even though `bfloat16` also works in practice, we do not
enable it since it's not specified in the extension (which might need
updating / promoting to KHR at least). A `TODO` is also inserted in
`SPIRVModuleAnalysis.cpp' regarding the need to upgrade its ample usage
of `report_fatal_error`; I have a WiP patch for that, but it still needs
a bit of baking. Finally, a paired patch will be necessary in the
Translator, as it's not aware of the extension either - I'll update this
review to reference the PR once I create it.
2025-12-05 20:23:25 +00:00
Aadesh Premkumar
7494f3df14
[SPIRV] Added support for extension SPV_ALTERA_arbitrary_precision_fixed_point and name change of SPV_INTEL_arbitrary_precision_integers to SPV_ALTERA_arbitrary_precision_integers (#136085)
--Added support for extension SPV_ALTERA_arbitrary_precision_fixed_point
--Added test files for extension
SPV_ALTERA_arbitrary_precision_fixed_point
2025-11-30 18:44:51 -08:00
Juan Manuel Martinez Caamaño
e0c0075819
[SPIRV][AMD] Disable SPV_KHR_float_control2 for AMD flavored SPIRV (#169659)
AMD uses the translator to recover LLVM-IR from SPIRV.

Currently, the translator doesn't implement the
`SPV_KHR_float_controls2` extension (I'm working on it).
If this extension is used by the SPIRV module, we cannot translate it
back to LLVM-IR.

I'm working on the extension, but in the meantime, lets just disable it
when the target triple's vendor is `amd`.
2025-11-27 16:16:21 +01:00
Alex Voicu
6ef32188b5
[SPIRV] Add support for bfloat16 atomics via the SPV_INTEL_16bit_atomics extension (#166257)
This enables support for atomic RMW ops (add, sub, min and max to be
precise) with `bfloat16` operands, via the [SPV_INTEL_16bit_atomics
extension](https://github.com/intel/llvm/pull/20009). It's logically a
successor to #166031 (I should've used a stack), but I'm putting it up
for early review.

---------

Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
2025-11-09 17:26:14 +00:00
Aadesh Premkumar
47cf5a1b82
[SPIRV] Support for the extension SPV_ALTERA_blocking_pipes (#138675)
--Added support for the extension SPV_ALTERA_blocking_pipes
--Added test files for the extension SPV_ALTERA_blocking_pipes
2025-11-06 11:59:54 +01:00
Alex Voicu
2286118e6f
[SPIRV] Enable bfloat16 arithmetic (#166031)
Enable the `SPV_INTEL_bfloat16_arithmetic` extension, which allows arithmetic, relational and `OpExtInst` instructions to take `bfloat16` arguments. This patch only adds support to arithmetic and relational ops. The extension itself is rather fresh, but `bfloat16` is ubiquitous at this point and not supporting these ops is limiting.
2025-11-04 18:10:26 +02:00
Alex Voicu
2237a18f25
[SPIRV] Enable OpenCL max_work_group_size translation via SPV_INTEL_kernel_attributes (#165891)
This adds BE support for the
[`SPV_INTEL_kernel_attributes`](https://github.khronos.org/SPIRV-Registry/extensions/INTEL/SPV_INTEL_kernel_attributes.html)
extension. The extension is necessary to encode the rather useful
`max_work_group_size` kernel attribute, via `OpExecutionMode
MaxWorkgroupSizeINTEL`, which is the only Execution Mode added by the
extension that this patch adds full processing for. Future patches will
add the other Execution Modes and Capabilities. The test is adapted from
the equivalent Translator test; it depends on #165815.
2025-11-04 14:37:16 +00:00
Lucie Choi
a43c0cf77f
[SPIR-V] Generate SPIR-V instructions when 'enable-maximal-reconvergence' function attribute is set (#163682)
Implement maximal reconvergence in SPIR-V codegen.

Addresses https://github.com/llvm/llvm-project/issues/136930
2025-10-17 13:12:56 +02:00
YixingZhang007
f802acf32d
[SPIR-V] Add SPV_INTEL_predicated_io extension (#161591)
This PR introduces the support for the SPIR-V extension
`SPV_INTEL_predicated_io`. This extension adds predicated load and store
instructions. Predicated load performs load from memory if predicate is
true; otherwise, it uses default_value as a result. Predicated store
performs store of value to memory if predicate is true; otherwise, it
does nothing.

Reference Specification:

https://github.com/intel/llvm/blob/sycl/sycl/doc/design/spirv-extensions/SPV_INTEL_predicated_io.asciidoc
2025-10-08 23:29:01 +02:00
Ebin-McW
5d85d54feb
[SPIRV] Add support for the extension SPV_EXT_relaxed_printf_string_address_space (#160245)
Added support for the extension to support more storageclass for printf
strings.
2025-09-28 05:50:15 -07:00
YixingZhang007
f91e0bf160
[SPIRV] Add support for the SPIR-V extension SPV_KHR_bfloat16 (#155645)
This PR introduces the support for the SPIR-V extension
`SPV_KHR_bfloat16`. This extension extends the `OpTypeFloat` instruction
to enable the use of bfloat16 types with cooperative matrices and dot
products.

TODO:
Per the `SPV_KHR_bfloat16` extension, there are a limited number of
instructions that can use the bfloat16 type. For example, arithmetic
instructions like `FAdd` or `FMul` can't operate on `bfloat16` values.
Therefore, a future patch should be added to either emit an error or
fall back to FP32 for arithmetic in cases where bfloat16 must not be
used.

Reference Specification:

https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_bfloat16.asciidoc
2025-09-22 14:52:57 +02:00
Kazu Hirata
8483bf442e
[SPIRV] Use llvm::is_contained (NFC) (#155136)
We can pass a range to llvm::is_contained.
2025-08-23 22:20:15 -07:00
Steven Perron
a53e73e6ef
[SPIRV][HLSL] Add DXC compatibility option for extension (#151554)
The default behaviour in DXC is to allow all extesions the compiler
knows about. We did the same in clang: all extensions that clang knows
about. However, this causes the shader to use different extensions
because the two compilers have different sets of extensions.

To avoid using a new extension when moving from DXC to Clang, we add the
special DXC suboptions to `-fspv-extension`. If `-fspv-extension=DXC` is
used, then the available extensions will be those available in DXC.

---------

Co-authored-by: Chris B <beanz@abolishcrlf.org>
2025-08-21 14:43:29 +00:00
Steven Perron
0fb1057e40
[SPIRV] Filter disallowed extensions for env (#150051)
Not all SPIR-V extensions are allows in every environment. When we use
the `-spirv-ext=all` option, the backend currently believes that all
extensions can be used.

This commit filters out the extensions on the command line to remove
those that are not known to be allowed for the current environment.

Alternatives considered: I considered modifying the
SPIRVExtensionsParser::parse to use a different list of extensions for
"all" depending on the target triple. However that does not work because
the target triple is not available, and cannot be made available in a
reasonable way.

Fixes #147717

---------

Co-authored-by: Victor Lomuller <victor@codeplay.com>
2025-08-18 18:33:58 +00:00
YixingZhang007
c0fa432315
[SPIR-V] Add support for the SPIR-V extension SPV_INTEL_tensor_float32_conversion (#150090)
This PR introduces the support for the SPIR-V extension
`SPV_INTEL_tensor_float32_conversion` and the corresponding OpenCL
extension `cl_intel_tensor_float32_conversions`.
This extension introduces a rounding instruction that converts standard
32-bit floating-point values to the TensorFloat32 (TF32) format.

Reference Specification: 

https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_tensor_float32_conversion.asciidoc
2025-08-01 22:43:59 +02:00
Steven Perron
832cd2df0b
[SPIRV] Add option to add all KHR extensions (#145535)
In DXC, there is an option to enable all KHR extension. I would like to
extend the existing `-spirv-ext` backend commandline option to have the
same capability. It is like the special case for `all` execept it only
adds the `SPV_KHR_*` extensions.

Part of https://github.com/llvm/llvm-project/issues/137650.
2025-07-02 13:50:48 -04:00
Steven Perron
4e213159af
[SPIRV] Add FloatControl2 capability (#144371)
Add handling for FPFastMathMode in SPIR-V shaders. This is a first pass
that
simply does a direct translation when the proper extension is available.
This will unblock work for HLSL. However, it is not a full solution.

The default math mode for spir-v is determined by the API. When
targeting Vulkan many of the fast math options are assumed. We should do
something particular when targeting Vulkan.

We will also need to handle the hlsl "precise" keyword correctly when
FPFastMathMode is not available.

Unblockes https://github.com/llvm/llvm-project/issues/140739, but we are
keeing it open to track the remaining issues mentioned above.
2025-07-02 08:48:57 -04:00
Viktoria Maximova
435d8b12ef
Reland [SPIR-V] Support SPV_INTEL_int4 extension (#141279)
This relands #141031 

This change ensures generated SPIR-V is valid and passes machine
verification:
```
*** Bad machine code: inconsistent constant size ***
- function:    foo
- basic block: %bb.1 entry (0x9ec9298)
- instruction: %12:iid(s8) = G_CONSTANT i4 1
```
That is done by promoting `G_CONSTANT` instructions with small integer
types (e.g., `i4`) to `i8` if no extensions for "special" integer types
are enabled.
2025-05-26 14:15:27 +02:00
Dmitry Sidorov
69d6c1ff66
Revert "[SPIR-V] Support SPV_INTEL_int4 extension" (#141219)
Reverts llvm/llvm-project#141031
2025-05-23 11:45:55 +02:00
Viktoria Maximova
ced6076dfc
[SPIR-V] Support SPV_INTEL_int4 extension (#141031)
Adds support for native 4-bit type.

Spec:

https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_int4.asciidoc
2025-05-22 11:56:54 -07:00
Iris Shi
bdf03fcff3
Revert "[llvm][NFC] Use llvm::sort()" (#140668) 2025-05-20 11:27:03 +08:00
Yury Plyakhin
755acb174a
[SPIR-V] Add SPV_INTEL_2d_block_io extension (#140140)
Adds additional subgroup block prefetch, load,
load transposed, load transformed and store
instructions to read two-dimensional blocks of
data from a two-dimensional region of memory, or
to write two-dimensional blocks of data to a
two-dimensional region of memory.

Spec:

https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_2d_block_io.asciidoc

---------

Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
2025-05-19 19:31:15 -07:00
Iris Shi
061a7699f3
[llvm][NFC] Use llvm::sort() (#140335) 2025-05-17 14:49:46 +08:00
Vyacheslav Levytskyy
8c47f23232
[SPIRV] Support for the SPV_INTEL_subgroup_matrix_multiply_accumulate SPIR-V extension (#135225)
Adds support for the SPV_INTEL_subgroup_matrix_multiply_accumulate
SPIR-V extension according to
https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_subgroup_matrix_multiply_accumulate.asciidoc
2025-04-23 12:11:01 +02:00
Kazu Hirata
20d35fe5a5
[llvm] Use llvm::is_contained (NFC) (#135566) 2025-04-13 16:35:29 -07:00
Steffen Larsen
f04bfbc416
[SPIRV] Support for SPV_INTEL_ternary_bitwise_function (#134866)
Adds support for the SPV_INTEL_ternary_bitwise_function extension,
adding;
* the OpBitwiseFunctionINTEL SPIR-V instruction, a ternary bitwise
function where the operation performed is determined by a look-up table
index,
 * and the corresponding TernaryBitwiseFunctionINTEL capability.

See
https://github.khronos.org/SPIRV-Registry/extensions/INTEL/SPV_INTEL_ternary_bitwise_function.html.

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
2025-04-09 10:02:43 +02:00
Rahul Joshi
a8a33bab69
[NFC][SPIRV] Misc code cleanup in SPIRV Target (#133764)
- Use static instead of anonymous namespace for file local functions.
- Enclose file-local classes in anonymous namespace.
- Eliminate `llvm::` qualifier when file has `using namespace llvm`.
- Eliminate namespace surrounding entire code in
SPIRVConvergenceRegionAnalysis.cpp file.
- Eliminate call to `initializeSPIRVStructurizerPass` from the pass
constructor (https://github.com/llvm/llvm-project/issues/111767)
2025-04-01 08:35:06 -07:00
Viktoria Maximova
a58a6a95b0
[SPIR-V] Support SPV_INTEL_fp_max_error extension for !fpmath metadata (#130619)
Specification:

https://github.khronos.org/SPIRV-Registry/extensions/INTEL/SPV_INTEL_fp_max_error.html
2025-03-14 12:12:28 +01:00
Dmitry Sidorov
7a44ff13d9
[SPIR-V] Add SPV_INTEL_memory_access_aliasing extension (#129800)
Spec can be found here https://github.com/intel/llvm/pull/15225
 TODO for future patches:
- During spec review need to decide whether only FunctionCall or Atomic
instructions can be decorated and if not - move the code around adding
handling for other instructions;
- Handle optional string metadata;
- Handle LLVM atomic instructions;
- Handle SPIR-V friendly atomic calls returning via sret argument.

Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
2025-03-06 19:44:21 +01:00
Viktoria Maximova
9ffab5637c
[SPIR-V] Initial implementation of SPV_INTEL_long_composites (#126545)
This change introduces support of `OpTypeStructContinuedINTEL`
instruction.

Specification:

https://github.khronos.org/SPIRV-Registry/extensions/INTEL/SPV_INTEL_long_composites.html
2025-02-20 16:09:06 +01:00
Dmitry Sidorov
55fa2fa348
[SPIR-V] Add SPV_INTEL_bindless_images extension (#127737)
Adds instructions to convert convert unsigned integer handles to images,
samplers and sampled images.

Spec:

https://github.com/intel/llvm/blob/sycl/sycl/doc/design/spirv-extensions/SPV_INTEL_bindless_images.asciidoc

---------

Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
2025-02-20 10:27:15 +01:00
Vyacheslav Levytskyy
df122fc734
[SPIR-V] Change a way SPIR-V Backend API works with user facing options (#124745)
This PR fixes https://github.com/llvm/llvm-project/issues/124703:
* added a new API call `SPIRVTranslate` that is to replace entirely old
`SPIRVTranslateModule` after existing clients switch into the new
function;
* the new `SPIRVTranslate` doesn't require option parsing, replacing the
`Opts` argument with explicit `CodeGenOptLevel` and `Triple` arguments;
* the old `SPIRVTranslateModule` call is a wrapper for `SPIRVTranslate`,
it doesn't require option parsing either and doesn't hold any logic
inside except for converting string options into `CodeGenOptLevel` and
`Triple` arguments;
* usage of the extensions list is reworked to avoid writes to the global
cl::opt variable `lib/Target/SPIRV/SPIRVSubtarget.cpp::Extensions` --
instead a new class member in SPIRVSubtarget.cpp is implemented that
allows to replace supported extensions after SPIRVSubtarget.cpp is
created;
* both API calls don't require option parsing and don't write to global
cl::opt variables.

Other related/required changes:
* SPIRV::Capability::Shader is marked as an capability of lesser
priority for OpenCL environment (to remediate absence of the
"avoid-spirv-capabilities" command line option in API calls);
* unit tests are updated and extended to cover testing of a newer API
call;
* old API call is marked with TODO to remove it after existing clients
switch into the new function.
2025-01-28 17:33:11 +01:00
Vyacheslav Levytskyy
978de2d666
[SPIR-V] Add saturation and float rounding mode decorations, a subset of arithmetic constrained floating-point intrinsics, and SPV_INTEL_float_controls2 extension (#119862)
This PR adds the following features:
* saturation and float rounding mode decorations,
* arithmetic constrained floating-point intrinsics (strict_fadd,
strict_fsub, strict_fmul, strict_fdiv, strict_frem, strict_fma and
strict_fldexp),
* and SPV_INTEL_float_controls2 extension,
* using recent improvements of emit-intrinsics step, this PR also
simplifies pre- and post-legalizer steps and improves instruction
selection.
2024-12-16 10:29:46 +01:00
Dmitry Sidorov
d057b53a7d
[SPIR-V] Add SPV_INTEL_joint_matrix extension (#118578)
The spec is available here:
https://github.com/intel/llvm/pull/12497

The PR doesn't add OpCooperativeMatrixApplyFunctionINTEL instruction as
it's still experimental and not properly tested E2E.

The PR also fixes few bugs in the related code:
1. CooperativeMatrixMulAddKHR optional operand must be literal, not a
constant;
2. Fixed available capabilities table creation for a case, when a single
extension adds few capabilities, that occupy not contiguous op codes.

---------

Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
2024-12-04 19:00:19 +01:00
Vyacheslav Levytskyy
874b4fb6ad
[SPIR-V] Fix emission of debug and annotation instructions and add SPV_EXT_optnone SPIR-V extension (#118402)
This PR fixes:
* emission of OpNames (added newly inserted internal intrinsics and
basic blocks)
* emission of function attributes (SRet is added)
* implementation of SPV_INTEL_optnone so that it emits OptNoneINTEL
Function Control flag, and add implementation of the SPV_EXT_optnone
SPIR-V extension.
2024-12-03 16:18:06 +01:00