[Mlir-commits] [mlir] Strenghten bytecode roundtrip test (PR #82946)
Matteo Franciolini
llvmlistbot at llvm.org
Sun Feb 25 18:15:06 PST 2024
https://github.com/mfrancio updated https://github.com/llvm/llvm-project/pull/82946
>From a282ea97ac067a23c449089f053021fab00198a3 Mon Sep 17 00:00:00 2001
From: Matteo Franciolini <mfranciolini at tesla.com>
Date: Sun, 25 Feb 2024 18:11:22 -0800
Subject: [PATCH] Enables textual IR roundtripping through `--verifyRoundtrip`
---
mlir/lib/Tools/mlir-opt/MlirOptMain.cpp | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index f01c7631decb77..8772bfd3518ced 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -276,6 +276,7 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
if (!irdlFile.empty() && failed(loadIRDLDialects(irdlFile, roundtripContext)))
return failure();
+ std::string testType = (useBytecode) ? "bytecode" : "textual";
// Print a first time with custom format (or bytecode) and parse it back to
// the roundtripModule.
{
@@ -289,7 +290,7 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
}
} else {
op->print(ostream,
- OpPrintingFlags().printGenericOpForm(false).enableDebugInfo());
+ OpPrintingFlags().printGenericOpForm().enableDebugInfo());
}
FallbackAsmResourceMap fallbackResourceMap;
ParserConfig parseConfig(&roundtripContext, /*verifyAfterParse=*/true,
@@ -297,8 +298,8 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
roundtripModule =
parseSourceString<Operation *>(ostream.str(), parseConfig);
if (!roundtripModule) {
- op->emitOpError()
- << "failed to parse bytecode back, cannot verify round-trip.\n";
+ op->emitOpError() << "failed to parse " << testType
+ << " content back, cannot verify round-trip.\n";
return failure();
}
}
@@ -317,10 +318,12 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
}
if (reference != roundtrip) {
// TODO implement a diff.
- return op->emitOpError() << "roundTrip testing roundtripped module differs "
- "from reference:\n<<<<<<Reference\n"
- << reference << "\n=====\n"
- << roundtrip << "\n>>>>>roundtripped\n";
+ return op->emitOpError()
+ << testType
+ << " roundTrip testing roundtripped module differs "
+ "from reference:\n<<<<<<Reference\n"
+ << reference << "\n=====\n"
+ << roundtrip << "\n>>>>>roundtripped\n";
}
return success();
@@ -328,9 +331,8 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
static LogicalResult doVerifyRoundTrip(Operation *op,
const MlirOptMainConfig &config) {
- // Textual round-trip isn't fully robust at the moment (for example implicit
- // terminator are losing location informations).
-
+ if (failed(doVerifyRoundTrip(op, config, /*useBytecode=*/false)))
+ return failure();
return doVerifyRoundTrip(op, config, /*useBytecode=*/true);
}
More information about the Mlir-commits
mailing list