[LLVMdev] Primer with LLVM

Francisco Puentes fpuentes at udc.es
Sat Jan 8 12:44:00 PST 2005


> > I have points 0-4 working, but I am confused about point 5 and maybe 6.
> [snip and reorder]
> > (5) Generate native (x86) code from generated module
> 
> The JIT currently is built to generate native code for a given module, a
> function-at-a-time.   That means that first, main() is generated, and
> anything main() calls is not.  As soon as main() calls anything that is
> in the Module that is NOT yet code-generated, it will be code-generated
> on-the-fly (aka just-in-time).
> 

Yes, i know.

> If you want to generate ALL the code for the entire Module at once, you
> will have to do one of the following:
> 
> 1. a) Compile to .asm file (using something like LLC)
>    b) Assemble the code using system assembler -> .o
>    c) Link it -> executable
>    d) Run executable
> 

Slowest.

> OR
> 
> 2. Modify the JIT to not run a function-at-a-time, but generate ALL the
> code for ALL the functions.  Note that this isn't supported at this
> time, so you will have to modify the ExecutionEngine
> (llvm/lib/ExecutionEngine/* and llvm/lib/ExecutionEngine/JIT/*) to do
> this.
> 

:-(

Well, i supposed that LLVM could generate native code: a raw memory segment
that contains machine code of a whole module.


> > (6) Localize entry point (¿main?)
> > (7) Execute it
> 
> llvm/tools/lli/lli.cpp ->
>     Function *Fn = MP->getModule()->getMainFunction();
>     if (!Fn) {
>       std::cerr << "'main' function not found in module.\n";
>       return -1;
>     }
> 
>     // Run main...
>     int Result = EE->runFunctionAsMain(Fn, InputArgv, envp);
> 

Yes, yes, I know it.

> See
> 
> llvm/lib/ExecutionEngine/ExecutionEngine.cpp for runFunctionAsMain()
> 
> --
> Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev





More information about the llvm-dev mailing list