[Mlir-commits] [mlir] 1bb48c4 - [mlir][emitc] Add literal op testing (NFC)

Gil Rapaport llvmlistbot at llvm.org
Sat Nov 4 10:48:52 PDT 2023


Author: Gil Rapaport
Date: 2023-11-04T19:47:38+02:00
New Revision: 1bb48c440b9299d251ec47d220f1c3a8db523041

URL: https://github.com/llvm/llvm-project/commit/1bb48c440b9299d251ec47d220f1c3a8db523041
DIFF: https://github.com/llvm/llvm-project/commit/1bb48c440b9299d251ec47d220f1c3a8db523041.diff

LOG: [mlir][emitc] Add literal op testing (NFC)

- Literal ops are emitted as unused variables under declare-variables-at-top
- Translator fails to emit literals used as emitc.call arguments

Added: 
    mlir/test/Target/Cpp/literal.mlir
    mlir/test/Target/Cpp/literal_call_operand.mlir

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/mlir/test/Target/Cpp/literal.mlir b/mlir/test/Target/Cpp/literal.mlir
new file mode 100644
index 000000000000000..19be1e83b5d0236
--- /dev/null
+++ b/mlir/test/Target/Cpp/literal.mlir
@@ -0,0 +1,15 @@
+// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
+// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
+
+func.func @emitc_literal(%arg0: f32) {
+  %p0 = emitc.literal "M_PI" : f32
+  %1 = "emitc.add" (%arg0, %p0) : (f32, f32) -> f32
+  return
+}
+// CPP-DEFAULT: void emitc_literal(float [[V0:[^ ]*]]) {
+// CPP-DEFAULT: float [[V2:[^ ]*]] = [[V0:[^ ]*]] + M_PI
+
+// CPP-DECLTOP: void emitc_literal(float [[V0:[^ ]*]]) {
+// CPP-DECLTOP: float M_PI;
+// CPP-DECLTOP: float [[V1:[^ ]*]];
+// CPP-DECLTOP: [[V1]] = [[V0:[^ ]*]] + M_PI

diff  --git a/mlir/test/Target/Cpp/literal_call_operand.mlir b/mlir/test/Target/Cpp/literal_call_operand.mlir
new file mode 100644
index 000000000000000..a41ee52449cf814
--- /dev/null
+++ b/mlir/test/Target/Cpp/literal_call_operand.mlir
@@ -0,0 +1,16 @@
+// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
+// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
+// XFAIL: *
+
+func.func @emitc_call_operand() {
+  %p0 = emitc.literal "M_PI" : f32
+  %1 = emitc.call "foo"(%p0) : (f32) -> f32
+  return
+}
+// CPP-DEFAULT: void emitc_call_operand() {
+// CPP-DEFAULT-NEXT: float v1 = foo(M_PI);
+
+// CPP-DECLTOP: void emitc_call_operand() {
+// CPP-DECLTOP-NEXT: float M_PI;
+// CPP-DECLTOP-NEXT: float v1;
+// CPP-DECLTOP-NEXT: v1 = foo(M_PI);


        


More information about the Mlir-commits mailing list