Print boolean values in ElementsAttr as "true"/"false"

We already parse boolean "true"/"false" as ElementsAttr elements.
This CL makes it round-trippable that we are printing the same way.

PiperOrigin-RevId: 258784962
This commit is contained in:
Lei Zhang 2019-07-18 09:24:41 -07:00 committed by Mehdi Amini
parent e558c040aa
commit 9f498f921b
2 changed files with 5 additions and 2 deletions

View File

@ -718,7 +718,10 @@ void ModulePrinter::printAttribute(Attribute attr, bool mayElideType) {
static void printDenseIntElement(DenseElementsAttr attr, raw_ostream &os,
unsigned index) {
APInt value = *std::next(attr.getIntValues().begin(), index);
value.print(os, /*isSigned=*/value.getBitWidth() != 1);
if (value.getBitWidth() == 1)
os << (value.getBoolValue() ? "true" : "false");
else
value.print(os, /*isSigned=*/true);
}
/// Print the float element of the given DenseElementsAttr at 'index'.

View File

@ -593,7 +593,7 @@ func @funcsimplemap(%arg0: index, %arg1: index) -> () {
// CHECK-LABEL: func @splattensorattr
func @splattensorattr() -> () {
^bb0:
// CHECK: "splatBoolTensor"() {bar = dense<0> : tensor<i1>} : () -> ()
// CHECK: "splatBoolTensor"() {bar = dense<false> : tensor<i1>} : () -> ()
"splatBoolTensor"(){bar = dense<false> : tensor<i1>} : () -> ()
// CHECK: "splatIntTensor"() {bar = dense<5> : tensor<2x1x4xi32>} : () -> ()