[PATCH] D78844: Sparse String Elements support.
Rob Suderman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 24 18:26:09 PDT 2020
rsuderman updated this revision to Diff 260048.
rsuderman added a comment.
Added getZeroValue() for string.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78844/new/
https://reviews.llvm.org/D78844
Files:
mlir/include/mlir/IR/Attributes.h
mlir/lib/IR/AsmPrinter.cpp
mlir/test/IR/parser.mlir
Index: mlir/test/IR/parser.mlir
===================================================================
--- mlir/test/IR/parser.mlir
+++ mlir/test/IR/parser.mlir
@@ -764,6 +764,11 @@
"foof320"(){bar = sparse<[], []> : tensor<0xf32>} : () -> ()
// CHECK: "foof321"() {bar = sparse<{{\[}}], {{\[}}]> : tensor<f32>} : () -> ()
"foof321"(){bar = sparse<[], []> : tensor<f32>} : () -> ()
+
+// CHECK: "foostr"() {bar = sparse<0, "foo"> : tensor<1x1x1x!unknown<"">>} : () -> ()
+ "foostr"(){bar = sparse<0, "foo"> : tensor<1x1x1x!unknown<"">>} : () -> ()
+// CHECK: "foostr"() {bar = sparse<{{\[\[}}1, 1, 0], {{\[}}0, 1, 0], {{\[}}0, 0, 1]], {{\[}}"a", "b", "c"]> : tensor<2x2x2x!unknown<"">>} : () -> ()
+ "foostr"(){bar = sparse<[[1, 1, 0], [0, 1, 0], [0, 0, 1]], ["a", "b", "c"]> : tensor<2x2x2x!unknown<"">>} : () -> ()
return
}
Index: mlir/lib/IR/AsmPrinter.cpp
===================================================================
--- mlir/lib/IR/AsmPrinter.cpp
+++ mlir/lib/IR/AsmPrinter.cpp
@@ -976,6 +976,11 @@
/// Print a dense string elements attribute.
void printDenseStringElementsAttr(DenseStringElementsAttr attr);
+ /// Print a dense elements attribute. If 'allowHex' is true, a hex string is
+ /// used instead of individual elements when the elements attr is large.
+ void printDenseIntOrFPElementsAttr(DenseIntOrFPElementsAttr attr,
+ bool allowHex);
+
void printDialectAttribute(Attribute attr);
void printDialectType(Type type);
@@ -1396,13 +1401,13 @@
break;
}
case StandardAttributes::DenseIntOrFPElements: {
- auto eltsAttr = attr.cast<DenseElementsAttr>();
+ auto eltsAttr = attr.cast<DenseIntOrFPElementsAttr>();
if (printerFlags.shouldElideElementsAttr(eltsAttr)) {
printElidedElementsAttr(os);
break;
}
os << "dense<";
- printDenseElementsAttr(eltsAttr, /*allowHex=*/true);
+ printDenseIntOrFPElementsAttr(eltsAttr, /*allowHex=*/true);
os << '>';
break;
}
@@ -1425,7 +1430,8 @@
break;
}
os << "sparse<";
- printDenseElementsAttr(elementsAttr.getIndices(), /*allowHex=*/false);
+ printDenseIntOrFPElementsAttr(elementsAttr.getIndices(),
+ /*allowHex=*/false);
os << ", ";
printDenseElementsAttr(elementsAttr.getValues(), /*allowHex=*/true);
os << '>';
@@ -1477,6 +1483,17 @@
void ModulePrinter::printDenseElementsAttr(DenseElementsAttr attr,
bool allowHex) {
+ if (auto stringAttr = attr.dyn_cast<DenseStringElementsAttr>()) {
+ printDenseStringElementsAttr(stringAttr);
+ return;
+ }
+
+ printDenseIntOrFPElementsAttr(attr.cast<DenseIntOrFPElementsAttr>(),
+ allowHex);
+}
+
+void ModulePrinter::printDenseIntOrFPElementsAttr(DenseIntOrFPElementsAttr attr,
+ bool allowHex) {
auto type = attr.getType();
auto shape = type.getShape();
auto rank = type.getRank();
Index: mlir/include/mlir/IR/Attributes.h
===================================================================
--- mlir/include/mlir/IR/Attributes.h
+++ mlir/include/mlir/IR/Attributes.h
@@ -1251,6 +1251,9 @@
/// Get a zero APInt for the given sparse attribute.
APInt getZeroAPInt() const;
+ /// Gets a zero (empty) stringref for the given sparse attribute.
+ StringRef getZeroString() const { return StringRef(); };
+
/// Get a zero attribute for the given sparse attribute.
Attribute getZeroAttr() const;
@@ -1274,6 +1277,9 @@
getZeroValue() const {
return getZeroAPFloat();
}
+
+ /// Get a zero for an APFloat.
+ StringRef getZeroValue() const { return getZeroString(); }
/// Get a zero for an C++ integer or float type.
template <typename T>
typename std::enable_if<std::numeric_limits<T>::is_integer ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78844.260048.patch
Type: text/x-patch
Size: 3875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200425/c41947e8/attachment.bin>
More information about the llvm-commits
mailing list