[Mlir-commits] [mlir] [MLIR][EmitC] Bugfix in emitc.call_opaque operand emission (PR #153980)

Gabriel Dehame llvmlistbot at llvm.org
Sun Aug 24 09:02:58 PDT 2025


https://github.com/gdehame updated https://github.com/llvm/llvm-project/pull/153980

>From c03d58f6dbba04909a2dc4f5d5dbdb4110164688 Mon Sep 17 00:00:00 2001
From: gdehame <gabrieldehame at gmail.com>
Date: Sat, 16 Aug 2025 23:41:06 +0200
Subject: [PATCH] Bugfix in emitc.call_opaque operand emission

The operand emission needed the operand to be in scope which lead to failure when the emitc.call_opaque is in an emitc.expression's body
---
 mlir/lib/Target/Cpp/TranslateToCpp.cpp |  6 +-----
 mlir/test/Target/Cpp/expressions.mlir  | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 8e83e455d1a7f..823176d6e08d8 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -749,11 +749,7 @@ static LogicalResult printOperation(CppEmitter &emitter,
       if (t.getType().isIndex()) {
         int64_t idx = t.getInt();
         Value operand = op.getOperand(idx);
-        if (!emitter.hasValueInScope(operand))
-          return op.emitOpError("operand ")
-                 << idx << "'s value not defined in scope";
-        os << emitter.getOrCreateName(operand);
-        return success();
+        return emitter.emitOperand(operand);
       }
     }
     if (failed(emitter.emitAttribute(op.getLoc(), attr)))
diff --git a/mlir/test/Target/Cpp/expressions.mlir b/mlir/test/Target/Cpp/expressions.mlir
index 9316d7b77619b..72e1a570103d3 100644
--- a/mlir/test/Target/Cpp/expressions.mlir
+++ b/mlir/test/Target/Cpp/expressions.mlir
@@ -399,3 +399,24 @@ func.func @expression_with_load_and_call(%arg0: !emitc.ptr<i32>) -> i1 {
   }
   return %result : i1
 }
+
+
+// CPP-DEFAULT: void expression_with_call_opaque_with_args_array(int32_t [[v1:v.+]], int32_t [[v2:v.+]]) {
+// CPP-DEFAULT-NEXT:   bool [[v3:v.+]] = f(([[v1]] < [[v2]]));
+// CPP-DEFAULT-NEXT:   return;
+// CPP-DEFAULT-NEXT: }
+
+// CPP-DECLTOP: void expression_with_call_opaque_with_args_array(int32_t [[v1:v.+]], int32_t [[v2:v.+]]) {
+// CPP-DECLTOP-NEXT:   bool [[v3:v.+]];
+// CPP-DECLTOP-NEXT:   [[v3]] = f(([[v1]] < [[v2]]));
+// CPP-DECLTOP-NEXT:   return;
+// CPP-DECLTOP-NEXT: }
+
+emitc.func @expression_with_call_opaque_with_args_array(%0 : i32, %1 : i32) {
+  %2 = expression : i1 {
+    %3 = cmp lt, %0, %1 : (i32, i32) -> i1
+    %4 = emitc.call_opaque "f"(%3) {"args" = [0: index]} : (i1) -> i1
+    yield %4 : i1
+  }
+  return
+}
\ No newline at end of file



More information about the Mlir-commits mailing list