[Mlir-commits] [mlir] [MLIR][Math] Add optional benefit arg to populate math lowering patterns (PR #127291)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Feb 14 17:26:11 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 625cb5a18576dd5d193da8d0249585cb5245da5c 282d90acb6c0a666fa115eb64ad1d26bb7565551 --extensions h,cpp -- mlir/include/mlir/Conversion/MathToLLVM/MathToLLVM.h mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp mlir/lib/Conversion/MathToLibm/MathToLibm.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/include/mlir/Conversion/MathToLLVM/MathToLLVM.h b/mlir/include/mlir/Conversion/MathToLLVM/MathToLLVM.h
index b7883fe9a5..9e6751efe8 100644
--- a/mlir/include/mlir/Conversion/MathToLLVM/MathToLLVM.h
+++ b/mlir/include/mlir/Conversion/MathToLLVM/MathToLLVM.h
@@ -23,7 +23,7 @@ class Pass;
 
 void populateMathToLLVMConversionPatterns(const LLVMTypeConverter &converter,
                                           RewritePatternSet &patterns,
-					  PatternBenefit benefit = 1,
+                                          PatternBenefit benefit = 1,
                                           bool approximateLog1p = true);
 
 void registerConvertMathToLLVMInterface(DialectRegistry &registry);
diff --git a/mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h b/mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h
index 6db661a7b5..8ace53a0fd 100644
--- a/mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h
+++ b/mlir/include/mlir/Conversion/MathToLibm/MathToLibm.h
@@ -19,7 +19,8 @@ class OperationPass;
 
 /// Populate the given list with patterns that convert from Math to Libm calls.
 /// If log1pBenefit is present, use it instead of benefit for the Log1p op.
-void populateMathToLibmConversionPatterns(RewritePatternSet &patterns, PatternBenefit benefit = 1);
+void populateMathToLibmConversionPatterns(RewritePatternSet &patterns,
+                                          PatternBenefit benefit = 1);
 
 /// Create a pass to convert Math operations to libm calls.
 std::unique_ptr<OperationPass<ModuleOp>> createConvertMathToLibmPass();
diff --git a/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp b/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp
index 196fad2d83..dd8d1f417b 100644
--- a/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp
+++ b/mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp
@@ -304,8 +304,7 @@ struct ConvertMathToLLVMPass
 
 void mlir::populateMathToLLVMConversionPatterns(
     const LLVMTypeConverter &converter, RewritePatternSet &patterns,
-    PatternBenefit benefit,
-    bool approximateLog1p) {
+    PatternBenefit benefit, bool approximateLog1p) {
   if (approximateLog1p)
     patterns.add<Log1pOpLowering>(converter, benefit);
   // clang-format off
diff --git a/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp b/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp
index 97ec5cf178..824bb5e35a 100644
--- a/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp
+++ b/mlir/lib/Conversion/MathToLibm/MathToLibm.cpp
@@ -50,10 +50,10 @@ template <typename Op>
 struct ScalarOpToLibmCall : public OpRewritePattern<Op> {
 public:
   using OpRewritePattern<Op>::OpRewritePattern;
-  ScalarOpToLibmCall(MLIRContext *context, PatternBenefit benefit, StringRef floatFunc,
-                     StringRef doubleFunc)
+  ScalarOpToLibmCall(MLIRContext *context, PatternBenefit benefit,
+                     StringRef floatFunc, StringRef doubleFunc)
       : OpRewritePattern<Op>(context, benegit, ), floatFunc(floatFunc),
-        doubleFunc(doubleFunc){};
+        doubleFunc(doubleFunc) {};
 
   LogicalResult matchAndRewrite(Op op, PatternRewriter &rewriter) const final;
 
@@ -62,8 +62,9 @@ private:
 };
 
 template <typename OpTy>
-void populatePatternsForOp(RewritePatternSet &patterns, PatternBenefit benefit, MLIRContext *ctx,
-                           StringRef floatFunc, StringRef doubleFunc) {
+void populatePatternsForOp(RewritePatternSet &patterns, PatternBenefit benefit,
+                           MLIRContext *ctx, StringRef floatFunc,
+                           StringRef doubleFunc) {
   patterns.add<VecOpToScalarOp<OpTy>, PromoteOpToF32<OpTy>>(ctx, benefit);
   patterns.add<ScalarOpToLibmCall<OpTy>>(ctx, benefit, floatFunc, doubleFunc);
 }
@@ -159,17 +160,22 @@ ScalarOpToLibmCall<Op>::matchAndRewrite(Op op,
   return success();
 }
 
-void mlir::populateMathToLibmConversionPatterns(RewritePatternSet &patterns, PatternBenefit benefit = 1) {
+void mlir::populateMathToLibmConversionPatterns(RewritePatternSet &patterns,
+                                                PatternBenefit benefit = 1) {
   MLIRContext *ctx = patterns.getContext();
 
   populatePatternsForOp<math::AbsFOp>(patterns, benefit, ctx, "fabsf", "fabs");
   populatePatternsForOp<math::AcosOp>(patterns, benefit, ctx, "acosf", "acos");
-  populatePatternsForOp<math::AcoshOp>(patterns, benefit, ctx, "acoshf", "acosh");
+  populatePatternsForOp<math::AcoshOp>(patterns, benefit, ctx, "acoshf",
+                                       "acosh");
   populatePatternsForOp<math::AsinOp>(patterns, benefit, ctx, "asinf", "asin");
-  populatePatternsForOp<math::AsinhOp>(patterns, benefit, ctx, "asinhf", "asinh");
-  populatePatternsForOp<math::Atan2Op>(patterns, benefit, ctx, "atan2f", "atan2");
+  populatePatternsForOp<math::AsinhOp>(patterns, benefit, ctx, "asinhf",
+                                       "asinh");
+  populatePatternsForOp<math::Atan2Op>(patterns, benefit, ctx, "atan2f",
+                                       "atan2");
   populatePatternsForOp<math::AtanOp>(patterns, benefit, ctx, "atanf", "atan");
-  populatePatternsForOp<math::AtanhOp>(patterns, benefit, ctx, "atanhf", "atanh");
+  populatePatternsForOp<math::AtanhOp>(patterns, benefit, ctx, "atanhf",
+                                       "atanh");
   populatePatternsForOp<math::CbrtOp>(patterns, benefit, ctx, "cbrtf", "cbrt");
   populatePatternsForOp<math::CeilOp>(patterns, benefit, ctx, "ceilf", "ceil");
   populatePatternsForOp<math::CosOp>(patterns, benefit, ctx, "cosf", "cos");
@@ -177,24 +183,31 @@ void mlir::populateMathToLibmConversionPatterns(RewritePatternSet &patterns, Pat
   populatePatternsForOp<math::ErfOp>(patterns, benefit, ctx, "erff", "erf");
   populatePatternsForOp<math::ExpOp>(patterns, benefit, ctx, "expf", "exp");
   populatePatternsForOp<math::Exp2Op>(patterns, benefit, ctx, "exp2f", "exp2");
-  populatePatternsForOp<math::ExpM1Op>(patterns, benefit, ctx, "expm1f", "expm1");
-  populatePatternsForOp<math::FloorOp>(patterns, benefit, ctx, "floorf", "floor");
+  populatePatternsForOp<math::ExpM1Op>(patterns, benefit, ctx, "expm1f",
+                                       "expm1");
+  populatePatternsForOp<math::FloorOp>(patterns, benefit, ctx, "floorf",
+                                       "floor");
   populatePatternsForOp<math::FmaOp>(patterns, benefit, ctx, "fmaf", "fma");
   populatePatternsForOp<math::LogOp>(patterns, benefit, ctx, "logf", "log");
   populatePatternsForOp<math::Log2Op>(patterns, benefit, ctx, "log2f", "log2");
-  populatePatternsForOp<math::Log10Op>(patterns, benefit, ctx, "log10f", "log10");
-  populatePatternsForOp<math::Log1pOp>(patterns, benefit, ctx, "log1pf", "log1p");
+  populatePatternsForOp<math::Log10Op>(patterns, benefit, ctx, "log10f",
+                                       "log10");
+  populatePatternsForOp<math::Log1pOp>(patterns, benefit, ctx, "log1pf",
+                                       "log1p");
   populatePatternsForOp<math::PowFOp>(patterns, benefit, ctx, "powf", "pow");
   populatePatternsForOp<math::RoundEvenOp>(patterns, benefit, ctx, "roundevenf",
                                            "roundeven");
-  populatePatternsForOp<math::RoundOp>(patterns, benefit, ctx, "roundf", "round");
+  populatePatternsForOp<math::RoundOp>(patterns, benefit, ctx, "roundf",
+                                       "round");
   populatePatternsForOp<math::SinOp>(patterns, benefit, ctx, "sinf", "sin");
   populatePatternsForOp<math::SinhOp>(patterns, benefit, ctx, "sinhf", "sinh");
   populatePatternsForOp<math::SqrtOp>(patterns, benefit, ctx, "sqrtf", "sqrt");
-  populatePatternsForOp<math::RsqrtOp>(patterns, benefit, ctx, "rsqrtf", "rsqrt");
+  populatePatternsForOp<math::RsqrtOp>(patterns, benefit, ctx, "rsqrtf",
+                                       "rsqrt");
   populatePatternsForOp<math::TanOp>(patterns, benefit, ctx, "tanf", "tan");
   populatePatternsForOp<math::TanhOp>(patterns, benefit, ctx, "tanhf", "tanh");
-  populatePatternsForOp<math::TruncOp>(patterns, benefit, ctx, "truncf", "trunc");
+  populatePatternsForOp<math::TruncOp>(patterns, benefit, ctx, "truncf",
+                                       "trunc");
 }
 
 namespace {

``````````

</details>


https://github.com/llvm/llvm-project/pull/127291


More information about the Mlir-commits mailing list