Skip to content

Commit

Permalink
[mlir] Gated calls to getAsm{Result,BlockArgument}Names on whether pr…
Browse files Browse the repository at this point in the history
…inting ops in generic form.

Depends On D105300

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D105301
  • Loading branch information
itaiz-google authored and joker-eph committed Jul 10, 2021
1 parent 2c0f179 commit ebbe149
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
12 changes: 7 additions & 5 deletions mlir/lib/IR/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ void SSANameState::numberValuesInBlock(Block &block) {
};

bool isEntryBlock = block.isEntryBlock();
if (isEntryBlock) {
if (isEntryBlock && !printerFlags.shouldPrintGenericOpForm()) {
if (auto *op = block.getParentOp()) {
if (auto asmInterface = interfaces.getInterfaceFor(op->getDialect()))
asmInterface->getAsmBlockArgumentNames(&block, setArgNameFn);
Expand Down Expand Up @@ -1038,10 +1038,12 @@ void SSANameState::numberValuesInOp(Operation &op) {
if (int resultNo = result.cast<OpResult>().getResultNumber())
resultGroups.push_back(resultNo);
};
if (OpAsmOpInterface asmInterface = dyn_cast<OpAsmOpInterface>(&op))
asmInterface.getAsmResultNames(setResultNameFn);
else if (auto *asmInterface = interfaces.getInterfaceFor(op.getDialect()))
asmInterface->getAsmResultNames(&op, setResultNameFn);
if (!printerFlags.shouldPrintGenericOpForm()) {
if (OpAsmOpInterface asmInterface = dyn_cast<OpAsmOpInterface>(&op))
asmInterface.getAsmResultNames(setResultNameFn);
else if (auto *asmInterface = interfaces.getInterfaceFor(op.getDialect()))
asmInterface->getAsmResultNames(&op, setResultNameFn);
}

// If the first result wasn't numbered, give it a default number.
if (valueIDs.try_emplace(resultBegin, nextValueID).second)
Expand Down
13 changes: 13 additions & 0 deletions mlir/test/IR/print-op-generic.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// # RUN: mlir-opt %s | FileCheck %s
// # RUN: mlir-opt %s --mlir-print-op-generic | FileCheck %s --check-prefix=GENERIC

// CHECK-LABEL: func @pretty_names
// CHECK-GENERIC: "func"()
func @pretty_names() {
%x = test.string_attr_pretty_name
// CHECK: %x = test.string_attr_pretty_name
// GENERIC: %0 = "test.string_attr_pretty_name"()
return
// CHECK: return
// GENERIC: "std.return"()
}
2 changes: 1 addition & 1 deletion mlir/test/mlir-lsp-server/hover.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// CHECK-NEXT: "result": {
// CHECK-NEXT: "contents": {
// CHECK-NEXT: "kind": "markdown",
// CHECK-NEXT: "value": "\"std.constant\"\n\nGeneric Form:\n\n```mlir\n%true = \"std.constant\"() {value = true} : () -> i1\n```\n"
// CHECK-NEXT: "value": "\"std.constant\"\n\nGeneric Form:\n\n```mlir\n%0 = \"std.constant\"() {value = true} : () -> i1\n```\n"
// CHECK-NEXT: },
// CHECK-NEXT: "range": {
// CHECK-NEXT: "end": {
Expand Down

0 comments on commit ebbe149

Please sign in to comment.