Hi all,
In [[mini-RFC] Name mangling in AOT](https://discuss.tvm.apache.org/t/mini-rfc-name-mangling-in-aot/9907), we discussed ways to accommodate the `runtime::Module` tree in an embedded environment, where we prefer to call functions directly in the generated C using their symbol name rather than looking them up at runtime via a string dictionary. Mangling was needed to namespace these functions. I think initially we viewed mangling as necessary for the top-level function names; therefore, we modified TECompilerImpl::Lower to produce PrimFuncs that contained module names. Since then, we've come to a number of challenges around mangled names: - tir.Constant may be declared as global variables by codegen; but then these names should really be mangled. - We introduced a new MetadataModule which defined a PrimFunc outside of TECompilerImpl::Lower which we use to support the PackedFunc-based AOTExecutor. Because this function was defined separately, its name wasn't mangled. This broke the multiple-model-in-the-same program use case. We had to work around this by [conditionally](https://github.com/apache/tvm/blob/main/src/target/source/source_module.cc#L823) mangling the function name depending which runtime was in use. Recall that mangling is needed in cases where two models are compiled into the same program--this turns out to surface itself mainly in the microTVM/C runtime use case, where we are not loading shared libraries. We were able to implement AOTExecutor in the C++ runtime because there, modules are compiled into `.so` and there is a mechanism to de-conflict symbol names which are duplicated across `.so`. In the C runtime we are not so lucky--all functions must be prefixed/mangled to avoid conflict. I propose we push all mangling out of the central compiler and into the codegen layer. This means that codegen would need to rewrite references to unmangled names as necessary--e.g. to tir.Constant, to tir.Call, and e.g. when generating FuncRegistry. This is somewhat burdensome on the C and LLVM codegens, but there, mangling is truly a property of the runtime environment and not necessarily something that needs to live in the central compiler. Would love to hear everyone's thoughts! cc @manupa-arm @Mousius @alanmacd @mbs-octoml @tqchen @junrushao1994 @jroesch Andrew --- [Visit Topic](https://discuss.tvm.apache.org/t/pre-rfc-name-mangling-in-irmodules/12944/1) to respond. You are receiving this because you enabled mailing list mode. To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/411e271da76ec9b2d3bdb857c10f8804408a6331e1ea9405d3af58a96964f387).