jroesch commented on a change in pull request #9483:
URL: https://github.com/apache/tvm/pull/9483#discussion_r758750447



##########
File path: src/relay/backend/vm/compiler.cc
##########
@@ -1125,55 +1105,52 @@ IRModule VMCompiler::OptimizeModuleImpl(IRModule mod) {
   }
 }
 
-void VMCompiler::PopulateGlobalMap() {
-  // First we populate global map.
-  size_t global_index = 0;
-  for (auto named_func : context_.module->functions) {
-    auto gvar = named_func.first;
-    context_.global_map.insert({gvar, global_index++});
+size_t VMCompiler::PopulateGlobalMap() {
+  // Allocate a VMFunction index for every Relay Function we could call.
+  // Excludes PrimFuncs and externs, which are managed by the primitive_map_.
+  for (const auto& kv : context_.module->functions) {
+    if (const auto* function_node = kv.second.as<FunctionNode>()) {
+      if (!function_node->GetAttr<String>(attr::kExternalSymbol)) {
+        context_.global_map.emplace(kv.first, context_.global_map.size());
+      }
+    }
   }
+  return context_.global_map.size();
 }
 
 void VMCompiler::Codegen() {
+  VLOG_CONTEXT << "VM Codegen";
   if (!context_.module.defined()) {
-    LOG(WARNING) << "Did you forget to call VMCompiler::Lower?";
-    return;
-  }
-  auto const& cached_funcs = context_.cached_funcs;
-  if (cached_funcs.size() == 0) {
+    LOG(WARNING) << "No compiled module to codegen from. Did you forget to 
call VMCompiler::Lower?";
     return;
   }
-  Map<Target, IRModule> funcs;
-
-  for (auto& cfunc : cached_funcs) {
-    Target target = cfunc->target;
-    // NOTE: because module, is mutable, we need to make an
-    // explicit copy of the IRModule.
-    IRModule mod = cfunc->funcs;
-    mod.CopyOnWrite();
-
-    if (target->kind->device_type == kDLExtDev) {
-      // Collect metadata in functions that are handled by external codegen.
-      auto name = cfunc->prim_fn_var->name_hint;
-      ICHECK(mod->ContainGlobalVar(name));
-      backend::UpdateConstants(mod->Lookup(name), &params_);
-    } else if (funcs.count(target) == 0) {
-      funcs.Set(target, mod);
-    } else {
-      funcs[target]->Update(mod);
-    }
-  }
 
-  auto ext_mods = context_.compiler->LowerExternalFunctions();
+  // At this point context_.module will contain only:

Review comment:
       Do we require the final build refactors to not require splitting here?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to