[Mlir-commits] [mlir] [mlir][emitc] Fix corner case in translation of literal ops (PR #71375)

Simon Camphausen llvmlistbot at llvm.org
Mon Nov 6 02:57:01 PST 2023


https://github.com/simon-camp created https://github.com/llvm/llvm-project/pull/71375

Fix a corner case missed in #71296 when operands generated by literals are mixed with the args attribute of a call op. Additionally remove a range check that is already done by the CallOp verifier.

>From ecd85a20ebc76c26ab72945f412ff9b2b210722b Mon Sep 17 00:00:00 2001
From: Simon Camphausen <simon.camphausen at iml.fraunhofer.de>
Date: Mon, 6 Nov 2023 10:48:24 +0000
Subject: [PATCH] [mlir][emitc] fix translation for literal op

---
 mlir/lib/Target/Cpp/TranslateToCpp.cpp         |  5 -----
 mlir/test/Target/Cpp/literal_call_operand.mlir | 12 ++++++++++++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 6c95eb3d20dacde..eeec9b11af7a0d0 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -425,11 +425,6 @@ static LogicalResult printOperation(CppEmitter &emitter, emitc::CallOp callOp) {
       // Index attributes are treated specially as operand index.
       if (t.getType().isIndex()) {
         int64_t idx = t.getInt();
-        if ((idx < 0) || (idx >= op.getNumOperands()))
-          return op.emitOpError("invalid operand index");
-        if (!emitter.hasValueInScope(op.getOperand(idx)))
-          return op.emitOpError("operand ")
-                 << idx << "'s value not defined in scope";
         os << emitter.getOrCreateName(op.getOperand(idx));
         return success();
       }
diff --git a/mlir/test/Target/Cpp/literal_call_operand.mlir b/mlir/test/Target/Cpp/literal_call_operand.mlir
index 017b4d53c43e3d8..428b66bb2519d9c 100644
--- a/mlir/test/Target/Cpp/literal_call_operand.mlir
+++ b/mlir/test/Target/Cpp/literal_call_operand.mlir
@@ -12,3 +12,15 @@ func.func @emitc_call_operand() {
 // CPP-DECLTOP: void emitc_call_operand() {
 // CPP-DECLTOP-NEXT: float v1;
 // CPP-DECLTOP-NEXT: v1 = foo(M_PI);
+
+func.func @emitc_call_operand_arg() {
+  %p0 = emitc.literal "M_PI" : f32
+  %1 = emitc.call "bar"(%p0) {args = [42 : i32, 0 : index]} : (f32) -> f32
+  return
+}
+// CPP-DEFAULT: void emitc_call_operand_arg() {
+// CPP-DEFAULT-NEXT: float v1 = bar(42, M_PI);
+
+// CPP-DECLTOP: void emitc_call_operand_arg() {
+// CPP-DECLTOP-NEXT: float v1;
+// CPP-DECLTOP-NEXT: v1 = bar(42, M_PI);



More information about the Mlir-commits mailing list