summaryrefslogtreecommitdiffstats
path: root/mlir/lib/IR
diff options
context:
space:
mode:
authorSean Silva <silvasean@google.com>2019-12-04 10:19:20 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-12-04 10:19:54 -0800
commit26484bc0b6ce2cf878afe75d0f13fd640a0529d1 (patch)
tree30742294c3a4125043b4d8eb3f172511c416a5b3 /mlir/lib/IR
parent0827fa562dc90fb3bed9f19ee4b0d36b0b5c3ac3 (diff)
downloadbcm5719-llvm-26484bc0b6ce2cf878afe75d0f13fd640a0529d1.tar.gz
bcm5719-llvm-26484bc0b6ce2cf878afe75d0f13fd640a0529d1.zip
Print out large elementsattr's such that they are parseable.
I found that when running crash reproducers, the elided elementsattr's would prevent parsing the IR repro. I found myself manually going and replacing the "..." with some valid IR. With this change, we now print elided attrs as `opaque<"", "0xDEADBEEF">` to clearly delineate them as being elided while still being parseable. PiperOrigin-RevId: 283781806
Diffstat (limited to 'mlir/lib/IR')
-rw-r--r--mlir/lib/IR/AsmPrinter.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 655a776118c..1d3f9d74403 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -733,6 +733,19 @@ static void printSymbolReference(StringRef symbolRef, raw_ostream &os) {
os << '"';
}
+// Print out a valid ElementsAttr that is succinct and can represent any
+// potential shape/type, for use when eliding a large ElementsAttr.
+//
+// We choose to use an opaque ElementsAttr literal with conspicuous content to
+// hopefully alert readers to the fact that this has been elided.
+//
+// Unfortunately, neither of the strings of an opaque ElementsAttr literal will
+// accept the string "elided". The first string must be a registered dialect
+// name and the latter must be a hex constant.
+static void printElidedElementsAttr(raw_ostream &os) {
+ os << R"(opaque<"", "0xDEADBEEF">)";
+}
+
void ModulePrinter::printAttribute(Attribute attr, bool mayElideType) {
if (!attr) {
os << "<<NULL ATTRIBUTE>>";
@@ -836,19 +849,20 @@ void ModulePrinter::printAttribute(Attribute attr, bool mayElideType) {
}
case StandardAttributes::OpaqueElements: {
auto eltsAttr = attr.cast<OpaqueElementsAttr>();
+ if (printerFlags.shouldElideElementsAttr(eltsAttr)) {
+ printElidedElementsAttr(os);
+ break;
+ }
os << "opaque<\"" << eltsAttr.getDialect()->getNamespace() << "\", ";
- os << '"' << "0x";
-
- // Check for large ElementsAttr elision.
- if (printerFlags.shouldElideElementsAttr(eltsAttr))
- os << "...";
- else
- os << llvm::toHex(eltsAttr.getValue());
- os << "\">";
+ os << '"' << "0x" << llvm::toHex(eltsAttr.getValue()) << "\">";
break;
}
case StandardAttributes::DenseElements: {
auto eltsAttr = attr.cast<DenseElementsAttr>();
+ if (printerFlags.shouldElideElementsAttr(eltsAttr)) {
+ printElidedElementsAttr(os);
+ break;
+ }
os << "dense<";
printDenseElementsAttr(eltsAttr);
os << '>';
@@ -856,6 +870,11 @@ void ModulePrinter::printAttribute(Attribute attr, bool mayElideType) {
}
case StandardAttributes::SparseElements: {
auto elementsAttr = attr.cast<SparseElementsAttr>();
+ if (printerFlags.shouldElideElementsAttr(elementsAttr.getIndices()) ||
+ printerFlags.shouldElideElementsAttr(elementsAttr.getValues())) {
+ printElidedElementsAttr(os);
+ break;
+ }
os << "sparse<";
printDenseElementsAttr(elementsAttr.getIndices());
os << ", ";
@@ -916,13 +935,6 @@ void ModulePrinter::printDenseElementsAttr(DenseElementsAttr attr) {
return;
}
- // Check for large elements attr elision. We explicitly check *after* splat,
- // as the splat printing is already elided.
- if (printerFlags.shouldElideElementsAttr(attr)) {
- os << "...";
- return;
- }
-
// Special case for degenerate tensors.
auto numElements = type.getNumElements();
if (numElements == 0) {
OpenPOWER on IntegriCloud