Skip to content

[mlir][emitc] Fix literal translation #71296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mlir/lib/Target/Cpp/TranslateToCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ static LogicalResult printOperation(CppEmitter &emitter,
// regions.
WalkResult result =
functionOp.walk<WalkOrder::PreOrder>([&](Operation *op) -> WalkResult {
if (isa<emitc::LiteralOp>(op))
return WalkResult::skip();
for (OpResult result : op->getResults()) {
if (failed(emitter.emitVariableDeclaration(
result, /*trailingSemicolon=*/true))) {
Expand Down Expand Up @@ -839,7 +841,8 @@ LogicalResult CppEmitter::emitAttribute(Location loc, Attribute attr) {

LogicalResult CppEmitter::emitOperands(Operation &op) {
auto emitOperandName = [&](Value result) -> LogicalResult {
if (!hasValueInScope(result))
auto literalDef = dyn_cast_if_present<LiteralOp>(result.getDefiningOp());
if (!literalDef && !hasValueInScope(result))
return op.emitOpError() << "operand value not in scope";
os << getOrCreateName(result);
return success();
Expand Down
1 change: 0 additions & 1 deletion mlir/test/Target/Cpp/literal.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ func.func @emitc_literal(%arg0: f32) {
// 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
2 changes: 0 additions & 2 deletions mlir/test/Target/Cpp/literal_call_operand.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// 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
Expand All @@ -11,6 +10,5 @@ func.func @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);