diff --git a/src/meta_schedule/integration.cc b/src/meta_schedule/integration.cc index ca83118df336..0b78c7711d15 100644 --- a/src/meta_schedule/integration.cc +++ b/src/meta_schedule/integration.cc @@ -26,8 +26,8 @@ namespace tvm { namespace meta_schedule { /**************** Utility functions ****************/ -template -Optional GetOnlyOneFunctionKey(const IRModule& mod) { +template +Optional GetOnlyOneFunctionCommon(const IRModule& mod, Callback on_found) { if (mod->functions.size() != 1) { return NullOpt; } @@ -36,26 +36,21 @@ Optional GetOnlyOneFunctionKey(const IRModule& mod) { if (!func->IsInstance()) { return NullOpt; } else { - return kv.first; + return on_found(kv); } } return NullOpt; } +template +Optional GetOnlyOneFunctionKey(const IRModule& mod) { + return GetOnlyOneFunctionCommon(mod, [](auto kv) { return kv.first; }); +} + template Optional GetOnlyOneFunction(const IRModule& mod) { - if (mod->functions.size() != 1) { - return NullOpt; - } - for (const auto& kv : mod->functions) { - const BaseFunc& func = kv.second; - if (!func->IsInstance()) { - return NullOpt; - } else { - return Downcast(func); - } - } - return NullOpt; + return GetOnlyOneFunctionCommon( + mod, [](auto kv) { return Downcast(kv.second); }); } template