Skip to content

Commit 4168756

Browse files
committed
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
1 parent f874092 commit 4168756

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
@@ -399,3 +399,24 @@ func.func @expression_with_load_and_call(%arg0: !emitc.ptr<i32>) -> i1 {
399399
}
400400
return %result : i1
401401
}
402+
403+
404+
// CPP-DEFAULT: void expression_with_call_opaque_with_args_array(int32_t [[v1:v.+]], int32_t [[v2:v.+]]) {
405+
// CPP-DEFAULT-NEXT: bool [[v3:v.+]] = f(([[v1]] < [[v2]]));
406+
// CPP-DEFAULT-NEXT: return;
407+
// CPP-DEFAULT-NEXT: }
408+
409+
// CPP-DECLTOP: void expression_with_call_opaque_with_args_array(int32_t [[v1:v.+]], int32_t [[v2:v.+]]) {
410+
// CPP-DECLTOP-NEXT: bool [[v3:v.+]];
411+
// CPP-DECLTOP-NEXT: [[v3]] = f(([[v1]] < [[v2]]));
412+
// CPP-DECLTOP-NEXT: return;
413+
// CPP-DECLTOP-NEXT: }
414+
415+
emitc.func @expression_with_call_opaque_with_args_array(%0 : i32, %1 : i32) {
416+
%2 = expression : i1 {
417+
%3 = cmp lt, %0, %1 : (i32, i32) -> i1
418+
%4 = emitc.call_opaque "f"(%3) {"args" = [0: index]} : (i1) -> i1
419+
yield %4 : i1
420+
}
421+
return
422+
}

0 commit comments

Comments
 (0)