-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir] Add OpAsmTypeInterface for pretty-print #121187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,27 @@ def OpAsmOpInterface : OpInterface<"OpAsmOpInterface"> { | |
]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// OpAsmTypeInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
def OpAsmTypeInterface : TypeInterface<"OpAsmTypeInterface"> { | ||
let description = [{ | ||
This interface provides hooks to interact with the AsmPrinter and AsmParser | ||
classes. | ||
}]; | ||
let cppNamespace = "::mlir"; | ||
|
||
let methods = [ | ||
InterfaceMethod<[{ | ||
Get a name to use when printing a value of this type. | ||
}], | ||
"void", "getAsmName", | ||
(ins "::mlir::OpAsmSetNameFn":$setNameFn), "", ";" | ||
Comment on lines
+127
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you instead follow the same API pattern as the getAlias function on OpAsmDialectInterface? |
||
>, | ||
]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// ResourceHandleParameter | ||
//===----------------------------------------------------------------------===// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: mlir-opt %s -split-input-file -verify-diagnostics | FileCheck %s | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Test OpAsmOpInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
func.func @result_name_from_op_asm_type_interface() { | ||
// CHECK-LABEL: @result_name_from_op_asm_type_interface | ||
// CHECK: %op_asm_type_interface | ||
%0 = "test.result_name_from_type"() : () -> !test.op_asm_type_interface | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
func.func @block_argument_name_from_op_asm_type_interface() { | ||
// CHECK-LABEL: @block_argument_name_from_op_asm_type_interface | ||
// CHECK: ^bb0(%op_asm_type_interface | ||
test.block_argument_name_from_type { | ||
^bb0(%arg0: !test.op_asm_type_interface): | ||
"test.terminator"() : ()->() | ||
} | ||
return | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -506,6 +506,38 @@ void CustomResultsNameOp::getAsmResultNames( | |
setNameFn(getResult(i), str.getValue()); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was expecting this to be backed into the AsmPrinter when it determines aliases, what is your current plan for implementation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Previous comment asked to split the integration with AsmPrinter into another PR. For testing purpose of this PR, I had to use a test op with custom OpAsmOpInterface to see if such interface is effective or not. My plan after this PR is to
|
||
// ResultNameFromTypeOp | ||
//===----------------------------------------------------------------------===// | ||
|
||
void ResultNameFromTypeOp::getAsmResultNames( | ||
function_ref<void(Value, StringRef)> setNameFn) { | ||
auto result = getResult(); | ||
auto setResultNameFn = [&](::llvm::StringRef name) { | ||
setNameFn(result, name); | ||
}; | ||
auto opAsmTypeInterface = | ||
::mlir::cast<::mlir::OpAsmTypeInterface>(result.getType()); | ||
opAsmTypeInterface.getAsmName(setResultNameFn); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// BlockArgumentNameFromTypeOp | ||
//===----------------------------------------------------------------------===// | ||
|
||
void BlockArgumentNameFromTypeOp::getAsmBlockArgumentNames( | ||
::mlir::Region ®ion, ::mlir::OpAsmSetValueNameFn setNameFn) { | ||
for (auto &block : region) { | ||
for (auto arg : block.getArguments()) { | ||
if (auto opAsmTypeInterface = | ||
::mlir::dyn_cast<::mlir::OpAsmTypeInterface>(arg.getType())) { | ||
auto setArgNameFn = [&](StringRef name) { setNameFn(arg, name); }; | ||
opAsmTypeInterface.getAsmName(setArgNameFn); | ||
} | ||
} | ||
} | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// ResultTypeWithTraitOp | ||
//===----------------------------------------------------------------------===// | ||
|
ZenithalHourlyRate marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.