@@ -22,6 +22,19 @@ namespace tvm {
2222namespace script {
2323namespace printer {
2424
25+ static 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+ static const EnvFunc fn = EnvFunc::Get (" tvm.relax.struct_info.infer_by_sinfo_args" );
32+ if (!fn.defined ()) {
33+ return false ;
34+ }
35+ return sinfo->derive_func .value ().same_as (fn);
36+ }
37+
2538bool AtTopLevelFunction (const IRDocsifier& d) {
2639 // fewer than 2 frames: not in a function at all
2740 if (d->frames .size () < 2 ) {
@@ -128,8 +141,12 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable)
128141TVM_STATIC_IR_FUNCTOR (IRDocsifier, vtable)
129142 .set_dispatch<relax::ExternFunc>( //
130143 " " , [](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)});
144+ ffi::Array<ExprDoc> args;
145+ args.push_back (LiteralDoc::Str (n->global_symbol , n_p->Attr (" global_symbol" )));
146+ if (!HasDefaultExternFuncStructInfo (n)) {
147+ args.push_back (d->AsDoc <ExprDoc>(n->struct_info_ , n_p->Attr (" struct_info_" )));
148+ }
149+ return Relax (d, " ExternFunc" )->Call (args);
133150 });
134151
135152TVM_SCRIPT_REPR (relax::FunctionNode, ReprPrintRelax);
0 commit comments