How to create compilable LLVM code from TVM?


I know that you can get LLVM code with:

graph,lib,params =,target,shape_dict,params=params)

But this code does not have a main function, so I can’t compile it for a specific backend with llc.
Is there a way that I can get it to put in a main function automatically?


Compiler here just build a library which packs functions for each operator in the model.

Main function here should be written by us which include initializing runtime, loading module, setting params and inputs …etc.

You may refer below doc for a sample.


Would this require me to also compile the rest of TVM for the new target? I’m trying to get the model to run on a riscv simulator.

Also, I noticed that there’s a function that’s seems to do this,CodeGenCPU::AddMainFunction that does execute but I’m not sure what it does.


Yes, you have to compile the tvm runtime for new target.


I wasn’t able to get the C++ example to build because of the include paths.