summaryrefslogtreecommitdiff
path: root/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp
AgeCommit message (Collapse)Author
2025-10-22[mlir] Switch uses of deprecated .create methods to free function. NFC. ↵Jakub Kuderski
(#164635) See https://discourse.llvm.org/t/psa-opty-create-now-with-100-more-tab-complete/87339.
2025-09-30[MLIR] Add sincos op to math dialect (#160772)Asher Mancinelli
Now that `sincos` is a supported intrinsic in the LLVM dialect (#160561) we are able to add the corresponding operation in the math dialect and add conversion patterns for LLVM and NVVM. We have several benchmarks that use sine and cosine in hot-loops, and saving some calculations by performing them together can benefit performance. We would like to have a way to represent sincos in the math dialect.
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-06-02[mlir][math] Fix intrinsic conversions to LLVM for 0D-vector types (#141020)Artem Gindinson
`vector<t>` types are not compatible with the LLVM type system – with the current approach employed within `LLVMTypeConverter`, they must be explicitly converted into `vector<1xt>` when lowering. Employ this rule within the conversion patterns for intrinsics that are handled directly within `MathToLLVM`: `math.ctlz` `.cttz`, `.absi`, `.expm1`, `.log1p`, `.rsqrt`, `.isnan`, `.isfinite`. This change does not cover/test patterns that are based off `VectorConvertToLLVMPattern` template from `LLVMCommon/VectorPattern.h`. --------- Signed-off-by: Artem Gindinson <gindinson@roofline.ai>
2025-05-27[mlir][math] Add missing trig math-to-llvm conversion patterns (#141069)Asher Mancinelli
asin, acos, atan, and atan2 were being lowered to libm calls instead of llvm intrinsics. Add the conversion patterns to handle these intrinsics and update tests to expect this.
2025-02-20[MLIR][Math] Add lowering for isnan and isfinite (#128125)William Moses
Co-authored-by: Ivan R. Ivanov <ivanov.i.aa@m.titech.ac.jp>
2025-02-14[MLIR][Math] Add optional benefit arg to populate math lowering patterns ↵William Moses
(#127291) Co-authored-by: Ivan R. Ivanov <ivanov.i.aa@m.titech.ac.jp>
2025-02-05[mlir] Add math to LLVM lowering support for missing trigonometric & ↵Paul Carabas
hyperbolic ops (#125753) The patch adds support for math -> LLVM dialect lowering for TanOp, Sinh, Cosh, Tanh
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-02-23[mlir][math] Propagate scalability in `convert-math-to-llvm` (#82635)Benjamin Maxwell
This also generally increases the coverage of scalable vector types in the math-to-llvm tests.
2023-08-09[mlir][Conversion] Implement ConvertToLLVMPatternInterface (2)Matthias Springer
Implement ConvertToLLVMPatternInterface for more dialects: index, math, ub. Differential Revision: https://reviews.llvm.org/D157478
2023-06-12[mlir][llvm] Ensure immediate usage in intrinsicsChristian Ulmann
This commit changes intrinsics that have immarg parameter attributes to model these parameters as attributes, instead of operands. Using operands only works if the operation is an `llvm.mlir.constant`, otherwise the exported LLVMIR is invalid. Reviewed By: gysit Differential Revision: https://reviews.llvm.org/D151692
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-02-21[mlir] Clean-up math -> libm/llvm conversion.Alexander Belyaev
At the moment, there is an optional log1pBenefit populateMathToLibmConversionPatterns which is used to increase the priority of the log1p->libm pattern compared to log1p->llvm pattern that approximates log1p with precision issues. Instead, we can have a flag for the MathToLLVM pass to enable or disable the imprecise approximation. Differential Revision: https://reviews.llvm.org/D144450
2023-02-10[mlir] Port Conversion Passes to LLVM to use TableGen generated constructors ↵Markus Böck
and options See https://github.com/llvm/llvm-project/issues/57475 for more context. Using auto-generated constructors and options has significant advantages: * It forces a uniform style and expectation for consuming a pass * It allows to very easily add, remove or change options to a pass by simply making the changes in TableGen * Its less code This patch in particular ports all the conversion passes which lower to LLVM to use the auto generated constructors and options. For the most part, care was taken so that auto generated constructor functions have the same name as they previously did. Only following slight breaking changes (which I consider as worth the churn) have been made: * `mlir::cf::createConvertControlFlowToLLVMPass` has been moved to the `mlir` namespace. This is consistent with basically all conversion passes * `createGpuToLLVMConversionPass` now takes a proper options struct array for its pass options. The pass options are now also autogenerated. * `LowerVectorToLLVMOptions` has been replaced by the autogenerated `ConvertVectorToLLVMPassOptions` which is automatically kept up to date by TableGen * I had to move one function in the GPU to LLVM lowering as it is used as default value for an option. * All passes that previously returned `unique_ptr<OperationPass<...>>` now simply return `unique_ptr<Pass>` Differential Revision: https://reviews.llvm.org/D143773
2022-12-14[mlir][math] Added math::FPowI conversion to LLVM dialect.Slava Zakharin
The operations are converted into LLVM::PowIOp. Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D129812
2022-11-04[mlir][math] Initial support for fastmath flag attributes for Math dialect.Slava Zakharin
Added arith::FastMathAttr and ArithFastMathInterface support for Math dialect floating point operations. This change-set creates ArithCommon conversion utils that currently provide classes and methods to aid with arith::FastMathAttr conversion into LLVM::FastmathFlags. These utils are used in ArithToLLVM and MathToLLVM convertors, but may eventually be used by other converters that need to convert fast math attributes. Since Math dialect operations use arith::FastMathAttr, MathOps.td now has to include enum and attributes definitions from Arith dialect. To minimize the amount of TD code included from Arith dialect, I moved FastMathAttr definition into ArithBase.td. Differential Revision: https://reviews.llvm.org/D136312
2022-09-09[mlir][Math] Add TruncOp.jacquesguan
This patch adds TruncOp for Math, it returns the operand rounded to the nearest integer not larger in magnitude than the operand. And this patch also adds the correspond llvm intrinsic op. Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D133342
2022-08-31[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
2022-08-30Revert "[MLIR] Update pass declarations to new autogenerated files"Michele Scuttari
This reverts commit 2be8af8f0e0780901213b6fd3013a5268ddc3359.
2022-08-30[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
2022-08-25[mlir] Add math.roundeven and llvm.intr.roundevenTres Popp
This is similar to math.round, but rounds to even instead of rounding away from zero in the case of halfway values. This CL also adds lowerings to libm and to the LLVM intrinsic. Differential Revision: https://reviews.llvm.org/D132375
2022-08-12[mlir][math] Fix lowering of AbsIOpJeff Niu
The LLVM intrinsic has a bool flag `is_int_min_poison` that needs to be set. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D131785
2022-08-09[mlir][LLVMIR] (NFC) Add convenience builders for ConstantOpJeff Niu
And clean up some of the user code
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-06-09[MLIR][Math] Re-order conversions alphabetically (NFC)lorenzo chelini
Minor follow-up after: D127286 (https://reviews.llvm.org/D127286/new/) Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D127382
2022-06-08[MLIR][Math] Add round operationlorenzo chelini
Introduce RoundOp in the math dialect. The operation rounds the operand to the nearest integer value in floating-point format. RoundOp lowers to LLVM intrinsics 'llvm.intr.round' or as a function call to libm (round or roundf). Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D127286
2022-05-16[mlir][tosa] Use math.ctlz intrinsic for tosa.clzRobert Suderman
We were custom counting per bit for the clz instruction. Math dialect now has an intrinsic to do this in one instruction. Migrated to this instruction and fixed a minor bug math-to-llvm for the intrinsic. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D125592
2022-01-18[mlir][Pass] Deprecate FunctionPass in favor of OperationPass<FuncOp>River Riddle
The only benefit of FunctionPass is that it filters out function declarations. This isn't enough to justify carrying it around, as we can simplify filter out declarations when necessary within the pass. We can also explore with better scheduling primitives to filter out declarations at the pipeline level in the future. The definition of FunctionPass is left intact for now to allow time for downstream users to migrate. Differential Revision: https://reviews.llvm.org/D117182
2021-12-08[mlir] Added ctlz and cttz to math dialect and LLVM dialectRob Suderman
Count leading/trailing zeros are an existing LLVM intrinsic. Added LLVM support for the intrinsics with lowerings from the math dialect to LLVM dialect. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D115206
2021-12-06[mlir] Add CtPop to MathOps with lowering to LLVMRob Suderman
math.ctpop maths to the llvm.ctpop intrinsic. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D114998
2021-11-30[mlir] Update accessors prefixed form (NFC)Jacques Pienaar
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:OpConversion] Remove the remaing usages of the deprecated ↵River Riddle
matchAndRewrite methods This commits updates the remaining usages of the ArrayRef<Value> based matchAndRewrite/rewrite methods in favor of the new OpAdaptor overload. Differential Revision: https://reviews.llvm.org/D110360
2021-07-16[mlir] replace llvm.mlir.cast with unrealized_conversion_castAlex Zinenko
The dialect-specific cast between builtin (ex-standard) types and LLVM dialect types was introduced long time before built-in support for unrealized_conversion_cast. It has a similar purpose, but is restricted to compatible builtin and LLVM dialect types, which may hamper progressive lowering and composition with types from other dialects. Replace llvm.mlir.cast with unrealized_conversion_cast, and drop the operation that became unnecessary. Also make unrealized_conversion_cast legal by default in LLVMConversionTarget as the majority of convesions using it are partial conversions that actually want the casts to persist in the IR. The standard-to-llvm conversion, which is still expected to run last, cleans up the remaining casts standard-to-llvm conversion, which is still expected to run last, cleans up the remaining casts Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D105880
2021-07-12[mlir] factor math-to-llvm out of standard-to-llvmAlex Zinenko
After the Math has been split out of the Standard dialect, the conversion to the LLVM dialect remained as a huge monolithic pass. This is undesirable for the same complexity management reasons as having a huge Standard dialect itself, and is even more confusing given the existence of a separate dialect. Extract the conversion of the Math dialect operations to LLVM into a separate library and a separate conversion pass. Reviewed By: silvas Differential Revision: https://reviews.llvm.org/D105702