summaryrefslogtreecommitdiff
path: root/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp
AgeCommit message (Collapse)Author
2025-11-20[mlir][spirv] Add support for SwitchOp (#168713)Igor Wodiany
The dialect implementation mostly copies the one of `cf.switch`, but aligns naming to the SPIR-V spec.
2025-10-27[mlir][spirv] Ensure function declarations precede definitions (#164956)Igor Wodiany
SPIR-V spec requires that any calls to external functions are preceded by declarations of those external functions. To simplify the implementation, we sort functions in the serializer using a stronger condition: any functions declarations are moved before any functions definitions - this ensures that external functions are always declared before being used.
2025-10-23[MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in ↵Mehdi Amini
Serializer.cpp (NFC)
2025-09-12[mlir][spirv] Add support for SPV_ARM_graph extension - part 2 (#156665)Davide Grohmann
This is the second patch to add support for the `SPV_ARM_graph` SPIR-V extension to MLIR’s SPIR-V dialect. The extension introduces a new `Graph` abstraction for expressing dataflow computations over full resources. The part 2 implementation includes: - Serialization and deserialization support for: - `OpGraphARM`, `OpGraphInputARM`, `OpGraphSetOutputARM`, `OpGraphEndARM` - `OpGraphEntryPointARM`, `OpGraphConstantARM`, `OpTypeGraphARM` - Tests covering binary round-tripping. Graphs currently support only `SPV_ARM_tensors`, but are designed to generalize to other resource types, such as images. Spec: https://github.com/KhronosGroup/SPIRV-Registry/pull/346 RFC: https://discourse.llvm.org/t/rfc-add-support-for-spv-arm-graph-extension-in-mlir-spir-v-dialect/86947 --------- Signed-off-by: Davide Grohmann <davide.grohmann@arm.com>
2025-08-13[mlir][spirv] Conditionally add SPV_KHR_non_semantic_info extension u… ↵Mohammadreza Ameri Mahabadian
(#152686) …pon serialization If serialization option `emitDebugInfo` is enabled, then it is required to serialize `SPV_KHR_non_semantic_info` extension provided that it is available in the target environment. --------- Signed-off-by: Mohammadreza Ameri Mahabadian <mohammadreza.amerimahabadian@arm.com>
2025-08-08[mlir][spirv] Fix serialization of TensorARM with rank higher than one (#152391)Mohammadreza Ameri Mahabadian
This PR fixes #152012 where serialization of TensorARM values into OpConstantComposite resulted in invalid binary. --------- Signed-off-by: Mohammadreza Ameri Mahabadian <mohammadreza.amerimahabadian@arm.com>
2025-08-06[mlir][spirv] Add support for Invariant and Patch decorations (#152301)Igor Wodiany
New tests were validated with `spriv-val`.
2025-08-01[mlir][spirv] Fix verification and serialization replicated constant … ↵Mohammadreza Ameri Mahabadian
(#151168) …composites of multi-dimensional array This fixes a bug in verification and serialization of replicated constant composite ops where the splat value can potentially be a multi-dimensional array. --------- Signed-off-by: Mohammadreza Ameri Mahabadian <mohammadreza.amerimahabadian@arm.com>
2025-08-01[mlir][spirv] Enable (de)serialization of TensorARM to/from OpConstan… ↵Mohammadreza Ameri Mahabadian
(#151485) …tNull This patch enables (de)serialization to/from OpConstantNull for null TensorARM --------- Signed-off-by: Mohammadreza Ameri Mahabadian <mohammadreza.amerimahabadian@arm.com>
2025-07-30[mlir][spirv] Fix serialization of multi-dimensional TensorArm constant ↵Mohammadreza Ameri Mahabadian
(#151158) This fixes an issue where multi-dimensional TensorArm dense elements could not be serialized. Signed-off-by: Mohammadreza Ameri Mahabadian <mohammadreza.amerimahabadian@arm.com>
2025-07-30[mlir][spirv] Add support for structs decorations (#149793)Igor Wodiany
An alternative implementation could use `ArrayRef` of `NamedAttribute`s or `NamedAttrList` to store structs decorations, as the deserializer uses `NamedAttribute`s for decorations. However, using a custom struct allows us to store the `spirv::Decoration`s directly rather than its name in a `StringRef`/`StringAttr`.
2025-07-28Reland "[mlir][spirv] Fix int type declaration duplication when serializing" ↵Davide Grohmann
(#145687) This relands PRs #143108 and #144538. The original PR was reverted due to a mistake that made all the mlir tests run only if SPIRV target was enabled. This is now resolved since enabling spirv-tools does not required SPIRV target any longer. spirv-tools are not required by default to run SPIRV mlir tests, but they can be optionally enabled in some SPIRV mlir test to verify that the produced SPIRV assembly pass validation. The other reverted PR #144685 is not longer needed and not part of this relanding. Original commit message: > At the MLIR level unsigned integer and signless integers are different types. Indeed when looking up the two types in type definition cache they do not match. > Hence when translating a SPIR-V module which contains both usign and signless integers will contain the same type declaration twice (something like OpTypeInt 32 0) which is not permitted in SPIR-V and such generated modules fail validation. > This patch solves the problem by mapping unisgned integer types to singless integer types before looking up in the type definition cache. --------- Signed-off-by: Davide Grohmann <davide.grohmann@arm.com>
2025-07-24[mlir] Remove unused includes (NFC) (#150476)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-07-24[mlir][spirv][nfc] Refactor member decorations in StructType (#150218)Igor Wodiany
This patch makes `==` and `<` for MemberDecorationInfo a friend function and removes a `hasValue` field. `decorationValue` is also made an `mlir::Attribute` so `UnitAttr` can be used to represent no-value. This is consistent with how OpDecorate is handled in the deserializer. Using `Attribute` will also enable handling non-integer values, however, there seem to be no such decorations for struct members now.
2025-07-15[mlir][spirv] Add basic support for SPV_EXT_replicated_composites (#147067)Mohammadreza Ameri Mahabadian
This patch introduces two new ops to the SPIR-V dialect: - `spirv.EXT.ConstantCompositeReplicate` - `spirv.EXT.SpecConstantCompositeReplicate` These ops represent composite constants and specialization constants, respectively, constructed by replicating a single splat constant across all elements. They correspond to `SPV_EXT_replicated_composites` extension instructions: - `OpConstantCompositeReplicatedEXT` - `OpSpecConstantCompositeReplicatedEXT` No transformation to these new ops has been introduced in this patch. This approach is chosen as per the discussions on RFC https://discourse.llvm.org/t/rfc-basic-support-for-spv-ext-replicated-composites-in-mlir-spir-v-compile-time-constant-lowering-only/86987 --------- Signed-off-by: Mohammadreza Ameri Mahabadian <mohammadreza.amerimahabadian@arm.com>
2025-07-02[mlir][spirv] Add support for SPV_ARM_tensors (#144667)Davide Grohmann
This patch introduces a new custom type `!spirv.arm.tensor<>` to the MLIR SPIR-V dialect to represent `OpTypeTensorARM` as defined in the `SPV_ARM_tensors` extension. The type models a shaped tensor with element type and optional shape, and implements the `ShapedType` interface to enable reuse of MLIR's existing shape-aware infrastructure. The type supports serialization to and from SPIR-V binary as `OpTypeTensorARM`, and emits the required capability (`TensorsARM`) and extension (`SPV_ARM_tensors`) declarations automatically. This addition lays the foundation for supporting structured tensor values natively in SPIR-V and will enable future support for operations defined in the `SPV_ARM_tensors` extension, such as `OpTensorReadARM`, `OpTensorWriteARM`, and `OpTensorQuerySizeARM`. Reference: https://github.com/KhronosGroup/SPIRV-Registry/pull/342 --------- Signed-off-by: Davide Grohmann <davide.grohmann@arm.com> Signed-off-by: Mohammadreza Ameri Mahabadian <mohammadreza.amerimahabadian@arm.com>
2025-06-18Revert "[mlir][spirv] Fix int type declaration duplication when serializing" ↵Jakub Kuderski
and follow up commits (#144773) This reverts the following PRs: * https://github.com/llvm/llvm-project/pull/143108 * https://github.com/llvm/llvm-project/pull/144538 * https://github.com/llvm/llvm-project/pull/144685 Reverting because this disabled tests when building without the llvm spirv backend enabled.
2025-06-17[mlir][spirv] Fix int type declaration duplication when serializing (#143108)Davide Grohmann
At the MLIR level unsigned integer and signless integers are different types. Indeed when looking up the two types in type definition cache they do not match. Hence when translating a SPIR-V module which contains both usign and signless integers will contain the same type declaration twice (something like OpTypeInt 32 0) which is not permitted in SPIR-V and such generated modules fail validation. This patch solves the problem by mapping unisgned integer types to singless integer types before looking up in the type definition cache. --------- Signed-off-by: Davide Grohmann <davide.grohmann@arm.com>
2025-06-13[mlir][spirv] Add bfloat16 support (#141458)Darren Wihandi
Adds bf16 support to SPIRV by using the `SPV_KHR_bfloat16` extension. Only a few operations are supported, including loading from and storing to memory, conversion to/from other types, cooperative matrix operations (including coop matrix arithmetic ops) and dot product support. This PR adds the type definition and implements the basic cast operations. Arithmetic/coop matrix ops will be added in a separate PR.
2025-06-10[mlir][spirv] Deserialize OpConstantComposite of type Cooperative Matrix ↵Igor Wodiany
(#142786) Depends on #142784.
2025-05-21[mlir] Remove unused local variables (NFC) (#140990)Kazu Hirata
2024-11-18[MLIR][SPIRV] Add definition and (de)serialization for cache controls (#115461)Victor Perez
[SPV_INTEL_cache_controls](https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_cache_controls.html) defines decorations for load and store cache control. Add support for this extension in the SPIR-V dialect. As several `CacheControlLoadINTEL` and `CacheControlStoreINTEL` may be applied to the same value, these are represented as array attributes. (De)Serialization takes care of this representation. --------- Signed-off-by: Victor Perez <victor.perez@codeplay.com>
2024-09-30[mlir][spirv] Add gpu printf op lowering to spirv.CL.printf op (#78510)Dimple Prajapati
This change contains following: - adds lowering of printf op to spirv.CL.printf op in GPUToSPIRV pass. - Fixes Constant decoration parsing for spirv GlobalVariable. - minor modification to spirv.CL.printf op assembly format. --------- Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
2024-09-15[mlir] Reland 5a6e52d6ef96d2bcab6dc50bdb369662ff17d2a0 with update (NFC)JOE1994
Excluded updates to mlir/lib/AsmParser/Parser.cpp , which caused LIT failure "FAIL: MLIR::completion.test" on multiple buildbots.
2024-09-15Revert "[mlir] Nits on uses of llvm::raw_string_ostream (NFC)"JOE1994
This reverts commit 5a6e52d6ef96d2bcab6dc50bdb369662ff17d2a0. "FAIL: MLIR::completion.test" on multiple buildbots.
2024-09-15[mlir] Nits on uses of llvm::raw_string_ostream (NFC)JOE1994
* Strip calls to raw_string_ostream::flush(), which is essentially a no-op * Strip unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
2024-08-13[mlir][spirv] Drop support for SPV_INTEL_joint_matrix (#102332)Andrea Faulds
This was a "preview" extension, never formalized, that has now been supplanted by SPV_KHR_cooperative_matrix.
2024-08-01[mlir][spirv] Add definitions and (de)serialization for FPRoundingMode (#101546)Andrea Faulds
2024-07-02mlir/LogicalResult: move into llvm (#97309)Ramkumar Ramachandra
This patch is part of a project to move the Presburger library into LLVM.
2024-04-13[mlir][spirv] Add op decoration NoContraction (#88578)Hsiangkai Wang
2024-04-01[mlir][NFC] Simplify type checks with isa predicates (#87183)Jakub Kuderski
For more context on isa predicates, see: https://github.com/llvm/llvm-project/pull/83753.
2024-02-17[mlir][spirv] Replace hardcoded strings with op methods (#81443)SahilPatidar
Progress towards #77627 --------- Co-authored-by: SahilPatidar <patidarsahil@2001gmail.com> Co-authored-by: Lei Zhang <antiagainst@gmail.com>
2024-01-08[mlir][spirv] Drop support for SPV_NV_cooperative_matrix (#76782)Jakub Kuderski
This extension has been superseded by SPV_KHR_cooperative_matrix which is supported across major vendors GPU like Nvidia, AMD, and Intel. Given that the KHR version has been supported for nearly half a year, drop the NV-specific extension to reduce the maintenance burden and code duplication.
2024-01-06[mlir][spirv] Support alias/restrict function argument decorations (#76353)Kohei Yamaguchi
Closes #76106 --------- Co-authored-by: Lei Zhang <antiagainst@gmail.com>
2023-11-21[mlir][spirv] Add some op decorations (#72809)Ivan Butygin
NoSignedWrap, NoUnsignedWrap, FPFastMathMode.
2023-10-24[ADT] Support appending multiple values (#69891)Jakub Kuderski
This is so that we can append multiple values at once without having to create a temporary array or repeatedly call `push_back`. Use the new function `append_values` to clean up the SPIR-V serializer code. (NFC)
2023-09-11[mlir][spirv] Support `spirv.coopmatrix` type (de-)serialization (#65831)Jakub Kuderski
Extend SPIR-V target serialization and deserialization to handle coop matrix types. Add a roundtrip test. In addition to `FileCheck` checks, the resulting spirv binary also passes `spir-val` (external tool). Also fix a type attribute bug surfaced by the `CooperativeMatrixLength` op. Multiple matrix operand attributes will be handled in a future patch to reduce the scope.
2023-06-05[mlir][spirv] Change numeric constant's bit-extension decision to be based ↵Md Abdullah Shahneous Bari
on type Integer constants with bit width less than a word (e.g., i8, i16) should be bit extended based on its type to be SPIR-V spec-compliant. Previously, the decision was based on the most significant bit of the value which ignores the signless semantics and causes problems when interfacing with SPIR-V tools. Dealing with numeric literals: the SPIR-V spec says, "If a numeric type’s bit width is less than 32-bits, the value appears in the low-order bits of the word, and the high-order bits must be 0 for a floating-point type or integer type with Signedness of 0, or sign extended for an integer type with a Signedness of 1 (similarly for the remaining bits of widths larger than 32 bits but not a multiple of 32 bits)." Therefore, signless integers (e.g., i8, i16) and unsigned integers should be 0-extended, and signed integers (e.g., si8, si16) should be sign-extended. Patch By: mshahneo Reviewed By: kuhar Differential Revision: https://reviews.llvm.org/D151767
2023-05-26[mlir] Move casting calls from methods to function callsTres Popp
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Context: - https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" - Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This patch updates all remaining uses of the deprecated functionality in mlir/. This was done with clang-tidy as described below and further modifications to GPUBase.td and OpenMPOpsInterfaces.td. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc ``` Differential Revision: https://reviews.llvm.org/D151542
2023-05-24[mlir][spirv] Support import/export Functions and GlobalVariablesMd Abdullah Shahneous Bari
"LinkageAttributes" decoration allow a SPIR-V module to import external functions and global variables, or export functions or global variables for other SPIR-V modules to link against and use. Import/export capability is extremely important when using outside libraries (e.g., intrinsic libraries). Added decorations: - LinkageAttributes Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D148749
2023-05-12[mlir] Move casting calls from methods to function callsTres Popp
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Caveats include: - This clang-tidy script probably has more problems. - This only touches C++ code, so nothing that is being generated. Context: - https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" - Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This first patch was created with the following steps. The intention is to only do automated changes at first, so I waste less time if it's reverted, and so the first mass change is more clear as an example to other teams that will need to follow similar steps. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. 4. Some changes have been deleted for the following reasons: - Some files had a variable also named cast - Some files had not included a header file that defines the cast functions - Some files are definitions of the classes that have the casting methods, so the code still refers to the method instead of the function without adding a prefix or removing the method declaration at the same time. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\ mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\ mlir/lib/**/IR/\ mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\ mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\ mlir/test/lib/Dialect/Test/TestTypes.cpp\ mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\ mlir/test/lib/Dialect/Test/TestAttributes.cpp\ mlir/unittests/TableGen/EnumsGenTest.cpp\ mlir/test/python/lib/PythonTestCAPI.cpp\ mlir/include/mlir/IR/ ``` Differential Revision: https://reviews.llvm.org/D150123
2023-01-14[mlir] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-13[mlir] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-09-26[mlir][spirv] Change dialect name from 'spv' to 'spirv'Jakub Kuderski
Tested with `check-mlir` and `check-mlir-integration`. Issue: https://github.com/llvm/llvm-project/issues/56863 Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D134620
2022-09-24[mlir][spirv] Switch to kEmitAccessorPrefix_PredixedJakub Kuderski
Fixes https://github.com/llvm/llvm-project/issues/57887 Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D134580
2022-08-15[MLIR][SPIRV] Add intel joint matrix opsNirvedh Meshram
Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D131586
2022-08-09[mlir][spirv] Migrate to use specalized enum attributesLei Zhang
Previously we are using IntegerAttr to back all SPIR-V enum attributes. Therefore we all such attributes are showed like IntegerAttr in IRs, which is barely readable and breaks roundtripability of the IR. This commit changes to use `EnumAttr` as the base directly so that we can have separate attribute definitions and better IR printing. Reviewed By: kuhar Differential Revision: https://reviews.llvm.org/D131311
2022-07-31[mlir] Remove types from attributesJeff Niu
This patch removes the `type` field from `Attribute` along with the `Attribute::getType` accessor. Going forward, this means that attributes in MLIR will no longer have types as a first-class concept. This patch lays the groundwork to incrementally remove or refactor code that relies on generic attributes being typed. The immediate impact will be on attributes that rely on `Attribute` containing a type, such as `IntegerAttr`, `DenseElementsAttr`, and `ml_program::ExternAttr`, which will now need to define a type parameter on their storage classes. This will save memory as all other attribute kinds will no longer contain a type. Moreover, it will not be possible to generically query the type of an attribute directly. This patch provides an attribute interface `TypedAttr` that implements only one method, `getType`, which can be used to generically query the types of attributes that implement the interface. This interface can be used to retain the concept of a "typed attribute". The ODS-generated accessor for a `type` parameter automatically implements this method. Next steps will be to refactor the assembly formats of certain operations that rely on `parseAttribute(type)` and `printAttributeWithoutType` to remove special handling of type elision until `type` can be removed from the dialect parsing hook entirely; and incrementally remove uses of `TypedAttr`. Reviewed By: lattner, rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D130092
2022-06-20[mlir] Don't use Optional::getValue (NFC)Kazu Hirata
2022-02-02[mlir] Refactor how additional verification is specified in ODSRiver Riddle
Currently if an operation requires additional verification, it specifies an inline code block (`let verifier = "blah"`). This is quite problematic for various reasons, e.g. it requires defining C++ inside of Tablegen which is discouraged when possible, but mainly because nearly all usages simply forward to a static function `static LogicalResult verify(SomeOp op)`. This commit adds support for a `hasVerifier` bit field that specifies if an additional verifier is needed, and when set to `1` declares a `LogicalResult verify()` method for operations to override. For migration purposes, the existing behavior is untouched. Upstream usages will be replaced in a followup to keep this patch focused on the hasVerifier implementation. One main user facing change is that what was one `MyOp::verify` is now `MyOp::verifyInvariants`. This better matches the name this method is called everywhere else, and also frees up `verify` for the user defined additional verification. The `verify` function when generated now (for additional verification) is private to the operation class, which should also help avoid accidental usages after this switch. Differential Revision: https://reviews.llvm.org/D118742