Skip to content

Commit 5e5fc64

Browse files
authored
[MLIR][EmitC] Bugfix in emitc.call_opaque operand emission (#153980)
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.
1 parent dbf34e5 commit 5e5fc64

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

mlir/lib/Target/Cpp/TranslateToCpp.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,7 @@ static LogicalResult printOperation(CppEmitter &emitter,
749749
if (t.getType().isIndex()) {
750750
int64_t idx = t.getInt();
751751
Value operand = op.getOperand(idx);
752-
if (!emitter.hasValueInScope(operand))
753-
return op.emitOpError("operand ")
754-
<< idx << "'s value not defined in scope";
755-
os << emitter.getOrCreateName(operand);
756-
return success();
752+
return emitter.emitOperand(operand);
757753
}
758754
}
759755
if (failed(emitter.emitAttribute(op.getLoc(), attr)))

mlir/test/Target/Cpp/expressions.mlir

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,24 @@ func.func @expression_with_load_and_call(%arg0: !emitc.ptr<i32>) -> i1 {
418418
}
419419
return %result : i1
420420
}
421+
422+
423+
// CPP-DEFAULT: void expression_with_call_opaque_with_args_array(int32_t [[v1:v.+]], int32_t [[v2:v.+]]) {
424+
// CPP-DEFAULT-NEXT: bool [[v3:v.+]] = f(([[v1]] < [[v2]]));
425+
// CPP-DEFAULT-NEXT: return;
426+
// CPP-DEFAULT-NEXT: }
427+
428+
// CPP-DECLTOP: void expression_with_call_opaque_with_args_array(int32_t [[v1:v.+]], int32_t [[v2:v.+]]) {
429+
// CPP-DECLTOP-NEXT: bool [[v3:v.+]];
430+
// CPP-DECLTOP-NEXT: [[v3]] = f(([[v1]] < [[v2]]));
431+
// CPP-DECLTOP-NEXT: return;
432+
// CPP-DECLTOP-NEXT: }
433+
434+
emitc.func @expression_with_call_opaque_with_args_array(%0 : i32, %1 : i32) {
435+
%2 = expression : i1 {
436+
%3 = cmp lt, %0, %1 : (i32, i32) -> i1
437+
%4 = emitc.call_opaque "f"(%3) {"args" = [0: index]} : (i1) -> i1
438+
yield %4 : i1
439+
}
440+
return
441+
}

0 commit comments

Comments
 (0)