[LLVMdev] Primer with LLVM

Misha Brukman brukman at uiuc.edu
Sat Jan 8 12:33:23 PST 2005


On Sat, Jan 08, 2005 at 06:16:47PM +0100, Francisco Puentes wrote:
> 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).

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

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.

> (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);

See

llvm/lib/ExecutionEngine/ExecutionEngine.cpp for runFunctionAsMain()

-- 
Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu




More information about the llvm-dev mailing list