[Mlir-commits] [mlir] 6c59f0e - [mlir][emitc] Fix literal translation (#71296)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Nov 5 17:06:28 PST 2023
Author: Gil Rapaport
Date: 2023-11-05T17:06:24-08:00
New Revision: 6c59f0e1b0fb56c909ad7c9aad4bde37dc006ae0
URL: https://github.com/llvm/llvm-project/commit/6c59f0e1b0fb56c909ad7c9aad4bde37dc006ae0
DIFF: https://github.com/llvm/llvm-project/commit/6c59f0e1b0fb56c909ad7c9aad4bde37dc006ae0.diff
LOG: [mlir][emitc] Fix literal translation (#71296)
- Do not emit variables-at-top for literals
- Do not emit an error for a missing name for literals used as call
operands.
Added:
Modified:
mlir/lib/Target/Cpp/TranslateToCpp.cpp
mlir/test/Target/Cpp/literal.mlir
mlir/test/Target/Cpp/literal_call_operand.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 8ffea4d5b7b3248..6c95eb3d20dacde 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -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))) {
@@ -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();
diff --git a/mlir/test/Target/Cpp/literal.mlir b/mlir/test/Target/Cpp/literal.mlir
index 19be1e83b5d0236..eff787611197738 100644
--- a/mlir/test/Target/Cpp/literal.mlir
+++ b/mlir/test/Target/Cpp/literal.mlir
@@ -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
diff --git a/mlir/test/Target/Cpp/literal_call_operand.mlir b/mlir/test/Target/Cpp/literal_call_operand.mlir
index a41ee52449cf814..017b4d53c43e3d8 100644
--- a/mlir/test/Target/Cpp/literal_call_operand.mlir
+++ b/mlir/test/Target/Cpp/literal_call_operand.mlir
@@ -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
@@ -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);
More information about the Mlir-commits
mailing list