summaryrefslogtreecommitdiff
path: root/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
AgeCommit message (Collapse)Author
2025-10-16[MLIR] Apply clang-tidy fixes for readability-identifier-naming in ↵Mehdi Amini
MathToSPIRV.cpp (NFC)
2025-09-18[mlir][spirv] Simplify inheriting constructor declarations. NFC. (#159681)Jakub Kuderski
Use the `Base` type alias from https://github.com/llvm/llvm-project/pull/158433.
2025-07-31[MLIR][SPIRV] Add spirv.IsFinite and lower math.{isfinite,isinf,isnan} to ↵Xiaolei Feng
spirv. (#151552) This patch adds support for lowering several float classification ops from the Math dialect to the SPIR-V dialect. ### Highlights: - Introduced a new `spirv.IsFinite` operation corresponding to the SPIR-V `OpIsFinite` instruction. - Lowered `math.isfinite`, `math.isinf`, and `math.isnan` to SPIR-V using `CheckedElementwiseOpPattern`. - Added corresponding tests for op definition and conversion lowering. This addresses the discussion in: https://github.com/llvm/llvm-project/issues/150778 --- Let me know if any additional adjustments are needed! --------- Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
2025-07-22[mlir][NFC] update `Conversion` create APIs (6/n) (#149888)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-04[mlir] Remove unused includes (NFC) (#147101)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-06-11[mlir][spirv] Add lowering of multiple math trig/hypb functions (#143604)Darren Wihandi
Add Math to SPIRV lowering for tan, asin, acos, sinh, cosh, asinh, acosh and atanh. This completes the lowering of all trigonometric and hyperbolic functions from math to SPIRV.
2024-10-09[mlir][spirv] Update math.powf lowering (#111388)Dmitriy Smirnov
The PR updates math.powf lowering to produce NaN result for a negative base with a fractional exponent which matches the actual behaviour of the C/C++ implementation.
2024-10-05[mlir][NFC] Mark type converter in `populate...` functions as `const` (#111250)Matthias Springer
This commit marks the type converter in `populate...` functions as `const`. This is useful for debugging. Patterns already take a `const` type converter. However, some `populate...` functions do not only add new patterns, but also add additional type conversion rules. That makes it difficult to find the place where a type conversion was added in the code base. With this change, all `populate...` functions that only populate pattern now have a `const` type converter. Programmers can then conclude from the function signature that these functions do not register any new type conversion rules. Also some minor cleanups around the 1:N dialect conversion infrastructure, which did not always pass the type converter as a `const` object internally.
2024-08-19[mlir][[spirv] Add support for math.log2 and math.log10 to GLSL/OpenCL SPIRV ↵meehatpa
Backends (#104608) As log2 and log10 are not available in spirv, realize them as a decomposition using spirv.CL.log/spirv.GL.Log.
2024-08-12[mlir][spirv] Add atan and atan2 pattern to MathToSPIRV Conversion pass ↵meehatpa
(#102633) Add missing math.atan to spirv.CL.atan and math.atan2 to spirv.CL.atan2 in MathToSPIRV. Add math.atan to spirv.GL.atan too.
2023-05-24[mlir][spirv] Add a missing pattern to MathToSPIRV Conversion passNishant Patel
The MathToSPIRV conversion pass missed out a pattern for converting math::AbsIOP to spirv::CLSAbsOp Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D151378
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-05-09[spirv][math] Fix sign propagation for math.powf conversionDaniel Garvey
For `x^y`, the result's sign should consider whether `y` is an integer and whether it's odd or even. This still does not cover all corner cases regarding `x^y` but it's an improvement over the current implementation. Reviewed By: antiagainst, qedawkins Differential Revision: https://reviews.llvm.org/D150234
2022-12-08[mlir][spirv] Support conversion of `CopySignOp` to spirv for 1D vector with ↵Guray Ozen
1 element Conversion of CopySignOp to SPIRV is supported for scalar and vectors but not 1D vectors with 1 element (aka vector<1xf32>). This revisions adds supports this by treating them as scalars. An alternative solution would be to allow 0D vectors for SPIRV, but the spec [0] strictly defines the vector type as non-0D. "Vector: An ordered homogeneous collection of two or more scalars. Vector sizes are quite restrictive and dependent on the execution model." [0] https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_types Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D139518
2022-11-17[mlir][spirv][math] Fix crash on unsupported types in math-to-spirvJakub Kuderski
Fail to match conversion patterns when source op has unsupported types. Fixes: https://github.com/llvm/llvm-project/issues/58749 Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D138178
2022-11-01[mlir][math][spirv] Add `math.roundeven` lowering to SPIR-VJakub Kuderski
This has two lowering path, one for each extended instructions set: - to OpenGL's `RoundEven`, - to OpenCL's `rint`. Implement those two ops and add minimal tests. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D137171
2022-08-08[mlir][math] Add `math.absi` opJeff Niu
Adds an integer absolute value op to the math dialect. When converting to LLVM, this op is lowered to the LLVM `abs` intrinsic. When converting to SPIRV, this op is lowered to `spv.GL.SAbs`. Depends on D131325 Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D131327
2022-08-08[mlir][math] Rename math.abs -> math.absfJeff Niu
To make room for introducing `math.absi`. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D131325
2022-07-21[mlir][spirv] Rename spv.GLSL ops to spv.GL. NFC.Jakub Kuderski
This is to improve consistency within the SPIR-V dialect and make these ops a bit shorter. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D130280
2022-07-20[mlir][spirv] Rename spv.ocl to spv.cl. NFC.Jakub Kuderski
This is to improve the consistency within the SPIR-V dialect and to make op names a bit shorter. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D130194
2022-07-07[mlir][spirv] Add path for math.round to spirv for OCL and GLSLRobert Suderman
OpenCL's round function matches `math.round` so we can directly lower to the op, this includes adding the op definition to the SPIRV OCL ops. GLSL does not guarantee rounding direction so we include custom rounding code to guarantee correct rounding direction. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D129236
2022-06-16[mlir][spirv] Workaround driver bug in math.ctlz conversion againLei Zhang
The previous approach does not work as the Adreno driver is clever at optimizing away the selection. So now check two inputs together. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D127930
2022-06-14[mlir][spirv] Handle corner cases for math.powf conversionLei Zhang
Per GLSL Pow extended instruction spec: "Result is undefined if x < 0. Result is undefined if x = 0 and y <= 0." So we need to handle negative `x` values specifically. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D127816
2022-06-14[mlir][spirv] Fix math.ctlz for full zero bit casesLei Zhang
If the integer has all zero bits, GLSL FindUMsb would return -1. So theoretically (31 - FindUMsb) should still give use the correct result. However, Adreno GPUshave issues with this: https://buildkite.com/iree/iree-test-android/builds/6482#01815f05-3926-466f-822a-1e20299e5461 This looks like a driver bug. So handle the corner case explicity to workaround it. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D127747
2022-06-13[mlir][spirv] Convert math.ctlz to spv.GLSL.FindUMsbLei Zhang
Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D127582
2022-05-03[mlir] Fix Visual Studio warningsStella Stamenova
There are only a couple of warnings when compiling with VS on Windows. This fixes the last remaining warnings so that we can enable LLVM_ENABLE_WERROR on the mlir windows bot. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D124862
2022-04-01[mlir][spirv] Add pattern to lower math.copysignLei Zhang
This follows the logic: https://git.musl-libc.org/cgit/musl/tree/src/math/copysignf.c Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D122910
2022-02-15[mlir][spirv] Add OpenCL fma op and loweringIvan Butygin
Also, it seems Khronos has changed html spec format so small adjustment to script was needed. Base op parsing is also probably broken. Differential Revision: https://reviews.llvm.org/D119678
2022-01-24[mlir] Add support for ExpM1 to GLSL/OpenCL SPIRV BackendsRob Suderman
Adding a similar decomposition for exponential minus one to the SPIRV backends along with the necessary tests. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D118081
2022-01-19[mlir][spirv] Add math.fma lowering to spirvThomas Raoux
Differential Revision: https://reviews.llvm.org/D117704
2021-12-08[mlir][spirv] math.erf OpenCL loweringButygin
Differential Revision: https://reviews.llvm.org/D115335
2021-11-30[mlir] Update accessors prefixed form (NFC)Jacques Pienaar
2021-11-24[mlir][spirv] Add math to OpenCL conversionButygin
Differential Revision: https://reviews.llvm.org/D113780
2021-10-13[MLIR] Replace std ops with arith dialect opsMogball
Precursor: https://reviews.llvm.org/D110200 Removed redundant ops from the standard dialect that were moved to the `arith` or `math` dialects. Renamed all instances of operations in the codebase and in tests. Reviewed By: rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D110797
2021-09-24[mlir:OpConversionPattern] Add overloads for taking an Adaptor instead of ↵River Riddle
ArrayRef This has been a TODO for a long time, and it brings about many advantages (namely nice accessors, and less fragile code). The existing overloads that accept ArrayRef are now treated as deprecated and will be removed in a followup (after a small grace period). Most of the upstream MLIR usages have been fixed by this commit, the rest will be handled in a followup. Differential Revision: https://reviews.llvm.org/D110293
2021-07-29[mlir] NFC: split Math to SPIR-V conversion into their own filesLei Zhang
Reviewed By: hanchung Differential Revision: https://reviews.llvm.org/D107093