* linker: run dedup earlier
Otherwise `linkings_to_do` might end up with stale IDs.
* linker: allow linking functions with different pointer arguments
Since llvm-17 there are no typed pointers and hte SPIRV-LLVM-Translator
doesn't know the function signature of imported functions.
I'm investigating different ways of solving this problem and adding an
option to work around it inside `spirv-link` is one of those.
The code is almost complete, just I'm having troubles constructing the
bitcast to cast the pointer parameters to the final type.
Closes: https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2153
* test/linker: add tests to test the AllowPtrTypeMismatch feature
When a trying to mark store that use the same address as a load live, we
consider any use of the pointer in the store instruction enough to make
the store live. This is not correct. We should only mark the store as
live if it store to the pointer, and not storing the pointer to another
memory location.
This causes DCE to miss some dead code.
* properly handle the load and store cache control operand types
Without handling these operand types, disassembling a SPIR-V module that uses the cache control extension produces an invalid operand type error.
* add a round trip test for SPV_INTEL_cache_controls
* opt: split composite from array flattening
DXC has an option to flatten resource arrays. But when this option
is not used, the resource arrays should be kept as-is.
On the other hand, when a struct contains resources, we MUST flatten is
to be compliant with the Vulkan spec.
Because this pass flattens both types of resources, using a struct of
resources automatically implied flattening arrays.
By adding those 2 new settings, we decide if the pass flattens only one type
of resources, or both.
Note: the flatten_arrays flag only impacts resource arrays.
Arrays of composites containing resources are still flattened.
Since the API is considered stable, I added 2 new functions to create
passes with one flag or the other, and kept the original behavior as-is.
Related to https://github.com/microsoft/DirectXShaderCompiler/issues/6745
Signed-off-by: Nathan Gauër <brioche@google.com>
* add commandline options
Signed-off-by: Nathan Gauër <brioche@google.com>
* clang-format
Signed-off-by: Nathan Gauër <brioche@google.com>
---------
Signed-off-by: Nathan Gauër <brioche@google.com>
* Support SPV_KHR_untyped_pointers
Covers:
- assembler
- disassembler
- validator
fix copyright
Validate OpTypeUntypedPointerKHR
* Disallow an untyped pointer in a typed pointer
* Validate capability requirements for untyped pointer
* Allow duplicate untyped pointer declarations
Add round trip tests
Validate OpUntypedVariableKHR
Validate untyped access chains
* Add a test for opcodes that generate untyped pointers
* simplify some checks for operands needing types
* validate OpUnypedAccessChainKHR, OpUntypedInBoundsAccessChainKHR,
OpUntypedPtrAccessChainKHR, OpUntypedInBoundsPtrAccessChainKHR
Unify variable validation
Validate OpCopyMemorySized
* Fix some opcode tests to accound for untyped pointers
* Add validation for OpCopyMemorySized for shaders and untyped pointers
* fix up tests
Validate pointer comparisons and bitcast
* Update more helpers
* Fix entry validation to allow OpUntypedVariableKHR
* Validate OpPtrEqual, OpPtrNotEqual and OpPtrDiff
* Validate OpBitcast
Validate atomics and untyped pointers
Make interface variable validation aware of untyped pointers
* Check OpUntypedVariableKHR in interface validation
More untyped pointer validation
* Validate interfaces more thoroughly
* Validate layouts for untyped pointer uses
* Improve capability checks for vulkan with OpTypeUntypedPointerKHR
* workgroup member explicit layout validation updates
More validation
* validate function arguments and parameters
* handle untyped pointer and variable in more places
Add a friendly assembly name for untyped pointers
Update OpCopyMemory validation and tests
Fix test for token update
Fixes for validation
* Allow typed pointers to contain untyped pointers
* Fix decoration validation
* add untyped pointer as a case for size and alignments
Fix interface validation
* Grabbed the wrong storage class operand for untyped variables
* Add ability to specify assembler options in validation tests
Add passthrough validation for OpUntypedArrayLengthKHR
More validation of untyped pointers
* Validate OpUntypedArrayLengthKHR
* Validate layout for OpLoad, OpStore, and OpUntypedArrayLengthKHR
Validation support for cooperative matrix and untyped pointers
* Allow untyped pointers for cooperative matrix KHR load and store
Updates to match spec
* Remove extra capability references
* Swap untyped variable data type and storage class operands
* update validation of variables
* update deps
---------
Co-authored-by: David Neto <dneto@google.com>
* In spirv-val allow format arg to printf to be an array of i8 in Generic space
Signed-off-by: Lu, John <john.lu@intel.com>
* Allow more addr spaces for printf format string
Signed-off-by: Lu, John <john.lu@intel.com>
* Update printf format arg testcase
Signed-off-by: Lu, John <john.lu@intel.com>
* Apply clang-format
Signed-off-by: Lu, John <john.lu@intel.com>
* Reorder code for clarity
Signed-off-by: Lu, John <john.lu@intel.com>
* Only allow other addr spaces if extension is seen
Signed-off-by: Lu, John <john.lu@intel.com>
* Add test to check printf format with extension
Signed-off-by: Lu, John <john.lu@intel.com>
* Add extension correctly
Signed-off-by: Lu, John <john.lu@intel.com>
---------
Signed-off-by: Lu, John <john.lu@intel.com>
Insert a placeholder enum that is never valid.
This allows compilation to pass on MSVC, which doesn't like
creating an array with explicit type elem[] but which has an empty
initializer.
Bug: crbug.com/351140758
This patch adds the optional FPEncoding operand that can be added to OpTypeFloat.
At the moment there is no usable operand, so support is limited to adding the entry.
Co-authored-by: Kévin Petit <kevin.petit@arm.com>
Co-authored-by: David Neto <dneto@google.com>
* Add knowledge of cooperative matrices
Some optimizations are not aware of cooperative matrices, and either do
nothing or assert. This commits fixes that up.
* Add int tests, and a handle a couple more cases.
* Add float tests, and a handle a couple more cases.
* Add NV coop matrix as well.
Fixing a clusterfuzz finding.
If the given binary has debug instruction which contained
a badly formatted ANSI escape sequence, the iteration could
go beyond the string length.
Signed-off-by: Nathan Gauër <brioche@google.com>
This explicit dep was removed in #5707 but it is still used by the test
library. Not sure why the Bazel build didn't catch the indirect
dependence on another module but it is causing build failures
downstream.
The folding rule `BitCastScalarOrVector` was incorrectly handling
bitcasting to unsigned integers smaller than 32-bits. It was simply
copying the entire 32-bit word containing the integer. This conflicts with the
requirement in section 2.2.1 of the SPIR-V spec which states that
unsigned numeric types with a bit width less than 32-bits must have the
high-order bits set to 0.
This change include a refactor of the bit extension code to be able to
test it better, and to use it in multiple files.
Fixes https://github.com/microsoft/DirectXShaderCompiler/issues/6319.
Those scripts are running on Python2.7 if build with the NDK tools.
Under python2.7, io.open will load as "utf-8" since we give the encoding
option, and return a "unicode" string.
Under Python3, the open() function will return a UTF-8 string.
This means the XMLParser needs to have a different 'encoding' option
depending on the python version.
For some reason I don't know, the XMLParser still fails if we use
'unicode' under Python2.7. But converting the unicode string to utf-8
does work.
Signed-off-by: Nathan Gauër <brioche@google.com>
With --nested-indent, the SPIR-V blocks are nested according to the
structured control flow. Each OpLabel is nested that much with the
contents of the block nested a little more. The blocks are separated by
a blank line for better visualization.
With --reorder-blocks, the SPIR-V blocks are reordered according to the
structured control flow. This is particularly useful with
--nested-indent.
Note that with --nested-indent, the disassembly does not exactly show
the binary as-is, and the instructions may be reordered.
This pass fixups the opcode used for OpExtInst instructions
to use OpExtInstWithForwardRefsKHR when it contains a forward
reference.
This pass is agnostic to the extension used, hence the validity
of the code depends of the validity of the usage:
If a forward reference is used on a non-semantic extended instruction,
the generated code will remain invalid, but the opcode will change.
What this pass guarantees is valid code won't become invalid.
---------
Signed-off-by: Nathan Gauër <brioche@google.com>
Co-authored-by: Steven Perron <stevenperron@google.com>
PR #5648 added support for the GroupNonUniformPartitionedNV. But there
was an issue: the opcodes are enabled by multiple capabilities, and the
actual operand is what matters.
Added testing coverage and the implementation to correctly trim a few
NonUniform capabilities.
Signed-off-by: Nathan Gauër <brioche@google.com>
The KHR suffix was missing from the published SPIR-V extension.
This is now fixed, but requires some patches in SPIRV-Tools.
Signed-off-by: Nathan Gauër <brioche@google.com>
* val, core: add support for OpExtInstWithForwardRefs
This commit adds validation and support for
OpExtInstWithForwardRefs. This new instruction will be used
for non-semantic debug info, when forward references are
required.
For now, this commit only fixes the code to handle this new instruction,
and adds validation rules. But it does not add the pass to generate/fix
the OpExtInst instruction when forward references are in use.
Such pass would be useful for DXC or other tools, but I wanted to land
validation rules first.
This commit also bumps SPIRV-Headers to get this new opcode.
---------
Signed-off-by: Nathan Gauër <brioche@google.com>
We replace getting the id of a poitner type with a specific funciton
call to FindPointerToType. Also, FindPointerToType is updated to not
indirectly call GetId. This leads to a linear search for an existing
type in all cases, but it is necessary.
Note that this function could have a similar problem. There could be two
pointer types with the same pointee and storage class, and the first one
will be returned. I have checked the ~20 uses, and they are all used in
situations where the id is used to create something new, and it does not
have to match an existing type. These will not cause problems.
Part of #5691
* Avoid use of type manager in extact->construct folding
When dealing with structs the type manager merge two different structs
into a single entry if they have all of the same decorations and
element types. This is because they hash to the same value in the hash
table. This can cause problems if you need to get the id of a type from
the type manager because you could get either one. In this case, it
returns the wrong one.
The fix avoids using the type manager in one place. I have not
looked closely at other places the type manager is used to make
sure it is used safely everywhere.
Fixes#5624
* Remove use of TypeManager::GetId
This removes a use of TypeManager::GetId by keeping the id around. This
avoid a potential problem if the type manager gets confused. These types
of bugs are hard to generate test cases for, so I do not have a test.
However, existing tests make sure that do not regress.
The last three elements in the list of supported targets were
misaligned:
```
Targets:
SPIR-V 1.0
SPIR-V 1.1
...
SPIR-V 1.3 (under Vulkan 1.1 semantics)
SPIR-V 1.4 (under Vulkan 1.1 semantics)
SPIR-V 1.5 (under Vulkan 1.2 semantics)
SPIR-V 1.6 (under Vulkan 1.3 semantics)
```
Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
* Basic support for SPV_EXT_replicated_composites
Validation will follow as a separate PR (still need to write a test suite)
Change-Id: Ic95fa6ce39d32f5ac2787bc38dba2748c9cc58f7
Signed-off-by: Kevin Petit <kevin.petit@arm.com>
* Update SPIRV-Headers
Change-Id: I6c0df248d99c13b49d78528d035a4222027c0232
---------
Signed-off-by: Kevin Petit <kevin.petit@arm.com>
This removes the folding rules added in #4783 and #4808. They lead to
poor code generation on Adreno devices when 16-bit floating point values
were used. Since this change is transformation is suppose to be neutral,
there is no general reason to continue doing it.
I have talked to the owners of SwiftShader, and they do not mind if the
transform is removed. They were the ones the requested the change in the
first place.
Fixes#5658
The autoroller does not update abseil, and that it stopping us from
updating RE2. This change will update the auto roller, then the next
time it runs, we should be able to update everything.
The Scope operand of `OpReadClockKHR` was always validated using the
Vulkan environment rules, which only allow `Subgroup` or `Device`.
For the OpenCL environment, `Workgroup` is also a valid Scope, so
`Workgroup` should not be rejected in the universal environment.
Guard the existing Scope check behind `spvIsVulkanEnv` and add a new
Scope check for the OpenCL environment.
Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
* Check for matrix decorations on arrays of matrices
* MatrixStide, RowMajor and ColMajor can be applied to matrix or
arrays of matrix members
* Check that matrix stride satisfies alignment in arrays