-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[IR] Support custom op printer #54499
[IR] Support custom op printer #54499
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
PrintGeneralOperation(op); | ||
} | ||
|
||
void IrPrinter::PrintGeneralOperation(Operation* op) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PrintGeneralOperation的实现是不是直接放在PrintOperation里就可以了?这样就可以把PrintGeneralOperation去掉,这俩函数定位理解起来有点儿不清晰。毕竟print_fn(op, *this); 后直接return了;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里PrintOperation事实上用于分发选择具体的print函数,我加注释说明下吧,个人认为还是分开比较好。
os << newline; | ||
} | ||
os << "}\n"; | ||
void IrPrinter::PrintProgram(Program* program) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PrintProgram不可以直接调用PrintFullOperation吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的意图是在print program时不输出顶层的builtin.module,不然会显得有点多余。后续会把region和block分拆到新函数,复用这部分代码
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
phi::IntArray int_array = | ||
attr.dyn_cast<paddle::dialect::IntArrayAttribute>().data(); | ||
|
||
ir::Builder builder = ir::Builder::AtBlockEnd(ctx, program->block()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这儿直接用 ir::Builder builder(ctx, program->block);就可以。 AtBlockEnd接口准备删除,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,下个PR修改一下。
|
||
void PrintType(Type type); | ||
|
||
void PrintAttribute(const Attribute& attr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attribute和Type的类型保持一致吧,要么都用const& ,要么都用临时值。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,下个PR修改一下,之后统一用临时值。
void IrPrinter::PrintProgram(Program* program) { | ||
auto top_level_op = program->module_op(); | ||
for (size_t i = 0; i < top_level_op->num_regions(); ++i) { | ||
auto& region = top_level_op->GetRegion(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么没有调用printRegion/printBlock函数?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是忘了,感谢提醒,下个PR修改下
PR types
Others
PR changes
Others
Description
This PR supports custom op printer, which allows custom dialects to define their own style to print an operation. For example, looks at
test/cpp/ir/core/ir_op_test.cc
.Meanwhile, we does the following changes:
IRPrinter
toIrPrinter
Others
Pcard-67164