Skip to content

Commit 092a469

Browse files
committed
Add additional information for ExternFunc
1 parent 5c17111 commit 092a469

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/script/printer/relax/function.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ namespace tvm {
2222
namespace script {
2323
namespace printer {
2424

25+
bool HasDefaultExternFuncStructInfo(const relax::ExternFunc& n) {
26+
const auto* sinfo = n->struct_info_.as<relax::FuncStructInfoNode>();
27+
if (sinfo == nullptr || sinfo->params.defined() || sinfo->purity ||
28+
!sinfo->ret->IsInstance<relax::ObjectStructInfoNode>() || !sinfo->derive_func.defined()) {
29+
return false;
30+
}
31+
EnvFunc fn = EnvFunc::Get("tvm.relax.struct_info.infer_by_sinfo_args");
32+
if (!fn.defined()) {
33+
return false;
34+
}
35+
relax::StructInfoDeriveFunc expected_derive = fn;
36+
return sinfo->derive_func.value().same_as(expected_derive);
37+
}
38+
2539
bool AtTopLevelFunction(const IRDocsifier& d) {
2640
// fewer than 2 frames: not in a function at all
2741
if (d->frames.size() < 2) {
@@ -128,8 +142,12 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable)
128142
TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable)
129143
.set_dispatch<relax::ExternFunc>( //
130144
"", [](relax::ExternFunc n, AccessPath n_p, IRDocsifier d) -> Doc {
131-
// TODO(@junrushao): print more information out of extern function.
132-
return Relax(d, "ExternFunc")->Call({LiteralDoc::Str(n->global_symbol, n_p)});
145+
ffi::Array<ExprDoc> args;
146+
args.push_back(LiteralDoc::Str(n->global_symbol, n_p->Attr("global_symbol")));
147+
if (!HasDefaultExternFuncStructInfo(n)) {
148+
args.push_back(d->AsDoc<ExprDoc>(n->struct_info_, n_p->Attr("struct_info_")));
149+
}
150+
return Relax(d, "ExternFunc")->Call(args);
133151
});
134152

135153
TVM_SCRIPT_REPR(relax::FunctionNode, ReprPrintRelax);

0 commit comments

Comments
 (0)