summaryrefslogtreecommitdiff
path: root/mlir/lib/Target/SPIRV/Serialization/SerializeOps.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-20[mlir][spirv] Remove destroyed values from ValueIDMap (#164098)Igor Wodiany
When serializing SPIR-V MLIR containing externally linked function with debug enabled, the serialization crashes as `printValueIDMap` tries to print a key value that has been already destroyed. This happen as for externally linked function the body of the function is erased, that causes arguments to be destroyed as well, but the valueIDMap was never updated.
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-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-04-30[mlir][spirv] Allow yielding values from loop regions (#135344)Igor Wodiany
This change extends `spirv.mlir.loop` so it can yield values, the same as `spirv.mlir.selection`.
2025-04-02[mlir][spirv] Allow yielding values from selection regions (#133702)Igor Wodiany
There are cases in SPIR-V shaders where values need to be yielded from the selection region to make valid MLIR. For example (part of the SPIR-V shader decompiled to GLSL): ``` bool _115 if (_107) { // ... float _200 = fma(...); // ... _115 = _200 < _174; } else { _115 = _107; } bool _123; if (_115) { // ... float _213 = fma(...); // ... _123 = _213 < _174; } else { _123 = _115; } ```` This patch extends `mlir.selection` so it can return values. `mlir.merge` is used as a "yield" operation. This allows to maintain a compatibility with code that does not yield any values, as well as, to maintain an assumption that `mlir.merge` is the only operation in the merge block of the selection region.
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-07-02mlir/LogicalResult: move into llvm (#97309)Ramkumar Ramachandra
This patch is part of a project to move the Presburger library into LLVM.
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-02-15Apply clang-tidy fixes for llvm-else-after-return in SerializeOps.cpp (NFC)Mehdi Amini
2024-01-06[mlir][spirv] Support alias/restrict function argument decorations (#76353)Kohei Yamaguchi
Closes #76106 --------- Co-authored-by: Lei Zhang <antiagainst@gmail.com>
2024-01-05[mlir][spirv] Support spec constants as GlobalVar initializer (#75660)Dimple Prajapati
Changes include: - spirv serialization and deserialization needs handling in cases when GlobalVariableOp initializer is defined using spirv SpecConstant or SpecConstantComposite op, currently even though it allows SpecConst, it only looked up in for GlobalVariable Map to find initializer symbol reference, change is fixing this and extending the support to SpecConstantComposite as an initializer. - Adds tests to make sure GlobalVariable can be initialized using specialized constants. --------- Co-authored-by: Lei Zhang <antiagainst@gmail.com>
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
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-09-20[mlir][spirv] Add casting ops to/from generic storage spaceNirvedh Meshram
Reviwed By: antiagainst Differential Revision: https://reviews.llvm.org/D134217
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-15Use drop_begin (NFC)Kazu Hirata
2022-06-20[mlir] Don't use Optional::getValue (NFC)Kazu Hirata
2022-03-16[mlir:FunctionOpInterface] Rename the "type" attribute to "function_type"River Riddle
This removes any potential confusion with the `getType` accessors which correspond to SSA results of an operation, and makes it clear what the intent is (i.e. to represent the type of the function). Differential Revision: https://reviews.llvm.org/D121762
2021-12-13[mlir][spirv] Serialize selection with separate header blockLei Zhang
The previous "optimization" that tries to reuse existing block for selection header block can be problematic for deserialization because it effectively pulls in previous ops in the selection op's enclosing block into the selection op's header. When deserializing, those ops will be placed in the selection op's region. If any of the previous ops has usage after the section op, it will break. That is, the following IR cannot round trip: ```mlir ^bb: %def = ... spv.mlir.selection { ... } %use = spv.SomeOp %def ``` This commit removes the "optimization" to always create new blocks for the selection header. Along the way, also made error reporting better in deserialization by turning asserts into proper errors and add check of uses outside of sinked structured control flow region blocks. Reviewed By: Hardcode84 Differential Revision: https://reviews.llvm.org/D115582
2021-12-11[mlir][spirv] Fix nested control flow serializationLei Zhang
If we have a `spv.mlir.selection` op nested in a `spv.mlir.loop` op, when serializing the loop's block, we might need to jump from the selection op's merge block, which might be different than the immediate MLIR IR predecessor block. But we still need to get the block argument from the MLIR IR predecessor block. Also, if the `spv.mlir.selection` is in the `spv.mlir.loop`'s header block, we need to make sure `OpLoopMerge` is emitted in the current block before start processing the nested selection op. Otherwise we'll see the LoopMerge in the wrong SPIR-V basic block. Reviewed By: Hardcode84 Differential Revision: https://reviews.llvm.org/D115560
2021-12-10[mlir][spirv] Propagate LogicalResult in (de)serializationLei Zhang
`(void)` was added when LogicalResult was marked as non discard. This commit cleans them up to properly propagate failures. Reviewed By: scotttodd Differential Revision: https://reviews.llvm.org/D115541
2021-12-10[mlir][spirv] Avoid duplicated Block decoration during serializationLei Zhang
It's legal per the Vulkan / SPIR-V spec; still it's better to avoid such duplication to have cleaner blob and reduce the binary size. Reviewed By: scotttodd Differential Revision: https://reviews.llvm.org/D115532
2021-11-18[mlir] Convert NamedAttribute to be a classRiver Riddle
NamedAttribute is currently represented as an std::pair, but this creates an extremely clunky .first/.second API. This commit converts it to a class, with better accessors (getName/getValue) and also opens the door for more convenient API in the future. Differential Revision: https://reviews.llvm.org/D113956
2021-03-06[MLIR][SPIRV] Rename `spv.selection` to `spv.mlir.selection`.KareemErgawy-TomTom
To unify the naming scheme across all ops in the SPIR-V dialect, we are moving from spv.camelCase to spv.CamelCase everywhere. For ops that don't have a SPIR-V spec counterpart, we use spv.mlir.snake_case. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D98014
2021-02-08[MLIR][SPIRV] NFC: Split serialization code among multiple files.KareemErgawy-TomTom
Following up on https://reviews.llvm.org/D94360, this patch splits the serialization code into multiple source files to provide a better structure and allow parallel compilation. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D95855