[Mlir-commits] [llvm] [mlir] [mlir][EmitC] Add MathToEmitC pass for math function lowering to EmitC (PR #113799)

Simon Camphausen llvmlistbot at llvm.org
Thu Nov 14 06:39:19 PST 2024


================
@@ -0,0 +1,133 @@
+// RUN: mlir-opt --split-input-file -convert-math-to-emitc -verify-diagnostics %s | FileCheck %s
+
+// CHECK-LABEL:   emitc.include "math.h"
+
+// CHECK-LABEL:   func.func @absf_to_call_opaque(
+// CHECK-SAME:                                   %[[VAL_0:.*]]: f32) {
+// CHECK:           %[[VAL_1:.*]] = emitc.call_opaque "fabs"(%[[VAL_0]]) : (f32) -> f32
+// CHECK:           return
+// CHECK:         }
+func.func @absf_to_call_opaque(%arg0: f32) {
+    %1 = math.absf %arg0 : f32
----------------
simon-camp wrote:

Can you make the tests exhaustive, with something like this:

```mlir
func.func @floor(%arg0: f32, %arg1: f64) {
    // C: emitc.call_opaque "floorf" (%arg0)
    // C-NEXT: emitc.call_opaque "floor" (%arg1)
    // CPP: emitc.call_opaque "std::floor" (%arg0)
    // CPP-NEXT: emitc.call_opaque "std::floor" (%arg1)
    %0 = math.floor %arg0 : f32
    %1 = math.floor %arg1 : f64
    return
}
```

Addiotionally a test for `math.round` is missing currently.

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


More information about the Mlir-commits mailing list