[all-commits] [llvm/llvm-project] c0055e: [mlir][EmitC] Add MathToEmitC pass for math functi...

Tomer Solomon via All-commits all-commits at lists.llvm.org
Mon Jan 20 00:27:02 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c0055ec434cbb132d7776f8b4c39e99b69fa97ea
      https://github.com/llvm/llvm-project/commit/c0055ec434cbb132d7776f8b4c39e99b69fa97ea
  Author: Tomer Solomon <tomsol2009 at gmail.com>
  Date:   2025-01-20 (Mon, 20 Jan 2025)

  Changed paths:
    A mlir/include/mlir/Conversion/MathToEmitC/MathToEmitC.h
    A mlir/include/mlir/Conversion/MathToEmitC/MathToEmitCPass.h
    M mlir/include/mlir/Conversion/Passes.h
    M mlir/include/mlir/Conversion/Passes.td
    M mlir/lib/Conversion/CMakeLists.txt
    A mlir/lib/Conversion/MathToEmitC/CMakeLists.txt
    A mlir/lib/Conversion/MathToEmitC/MathToEmitC.cpp
    A mlir/lib/Conversion/MathToEmitC/MathToEmitCPass.cpp
    A mlir/test/Conversion/MathToEmitC/math-to-emitc-failed.mlir
    A mlir/test/Conversion/MathToEmitC/math-to-emitc.mlir
    M utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

  Log Message:
  -----------
  [mlir][EmitC] Add MathToEmitC pass for math function lowering to EmitC (#113799)

This commit introduces a new MathToEmitC conversion pass that lowers
selected math operations from the Math dialect to the emitc.call_opaque
operation in the EmitC dialect.

**Supported Math Operations:**
The following operations are converted:

- math.floor -> emitc.call_opaque<"floor">
- math.round -> emitc.call_opaque<"round">
- math.exp -> emitc.call_opaque<"exp">
- math.cos -> emitc.call_opaque<"cos">
- math.sin -> emitc.call_opaque<"sin">
- math.acos -> emitc.call_opaque<"acos">
- math.asin -> emitc.call_opaque<"asin">
- math.atan2 -> emitc.call_opaque<"atan2">
- math.ceil -> emitc.call_opaque<"ceil">
- math.absf -> emitc.call_opaque<"fabs">
- math.powf -> emitc.call_opaque<"pow">

**Target Language Standards:**
The pass supports targeting different language standards:

- C99: Generates calls with suffixes (e.g., floorf, fabsf) for
single-precision floats.
- CPP11: Prepends std:: to functions (e.g., std::floor, std::fabs).

**Design Decisions:**
The pass uses emitc.call_opaque instead of emitc.call to better emulate
C-style function overloading.
emitc.call_opaque does not require a unique type signature, making it
more suitable for operations like <math.h> functions that may be
overloaded for different types.
This design choice ensures compatibility with C/C++ conventions.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list