resource keys have the problem that you can’t parse them from mlir
assembly if they have special or non-printable characters, but nothing
prevents you from specifying such a key when you create e.g. a
DenseResourceElementsAttr, and it works fine in other ways, including
bytecode emission and parsing
this PR solves the parsing by quoting and escaping keys with special or
non-printable characters in mlir assembly, in the same way as symbols,
e.g.:
```
module attributes {
fst = dense_resource<resource_fst> : tensor<2xf16>,
snd = dense_resource<"resource\09snd"> : tensor<2xf16>
} {}
{-#
dialect_resources: {
builtin: {
resource_fst: "0x0200000001000200",
"resource\09snd": "0x0200000008000900"
}
}
#-}
```
by not quoting keys without special or non-printable characters, the
change is effectively backwards compatible
the change is tested by:
1. adding a test with a dense resource handle key with special
characters to `dense-resource-elements-attr.mlir`
2. adding special and unprintable characters to some resource keys in
the existing lit tests `pretty-resources-print.mlir` and
`mlir/test/Bytecode/resources.mlir`
28 lines
846 B
MLIR
28 lines
846 B
MLIR
// RUN: mlir-opt -allow-unregistered-dialect %s -verify-diagnostics -split-input-file | FileCheck %s
|
|
|
|
// CHECK: attr = dense_resource<blob1> : tensor<3xi64>
|
|
"test.user_op"() {attr = dense_resource<blob1> : tensor<3xi64> } : () -> ()
|
|
|
|
{-#
|
|
dialect_resources: {
|
|
builtin: {
|
|
// CHECK: blob1: "0x08000000010000000000000002000000000000000300000000000000"
|
|
blob1: "0x08000000010000000000000002000000000000000300000000000000"
|
|
}
|
|
}
|
|
#-}
|
|
|
|
// -----
|
|
|
|
// DenseResourceElementsHandle key blob\-"one" is quoted and escaped.
|
|
// CHECK: attr = dense_resource<"blob\\-\22one\22"> : tensor<2xi16>
|
|
"test.user_op"() {attr = dense_resource<"blob\\-\22one\22"> : tensor<2xi16>} : () -> ()
|
|
|
|
{-#
|
|
dialect_resources: {
|
|
builtin: {
|
|
// CHECK: "blob\\-\22one\22": "0x0200000001000200"
|
|
"blob\\-\22one\22": "0x0200000001000200"
|
|
}
|
|
}
|
|
#-}
|