[LLVMdev] JIT API example (fibonacci)

Chris Lattner sabre at nondot.org
Tue Aug 17 15:47:02 PDT 2004


On Wed, 18 Aug 2004, Valery A.Khamenya wrote:

>   the example attached I have used to prove that JIT and some visible
>   optimizations are really invoked.
>
>   Proved OK. I got 30% speed-up in comparison to gcc 3.3.3
>   on my Athlon XP 1500.

Cool!  Hey Valery, before we add this to the CVS repo, can you take a look
at some of the changes I made to your HowToUseJIT example and use them to
simplify this example too?

For example, instead of code like this:

    // the type is 'int ()'
    std::vector<const Type*> ArgT(1);
    ArgT[0] = Type::IntTy;

    // now create full type of the "fib" function:
    FunctionType *FibT = FunctionType::get(Type::IntTy, // type of result
                                           ArgT,
                                           /*not vararg*/false);

    // Now create the fib function entry and
    // insert this entry into module M
    // (By passing a module as the last parameter to the Functionconstructor,
    // it automatically gets appended to the Module.)
    FibF = new Function(FibT,
                        Function::ExternalLinkage, // maybe too much
                        "fib", M);

You can do this same thing with code like this:

  Function *FibF = M->getOrInsertFunction("fib", Type::IntTy, Type::IntTy, 0);

Thanks!  I really like the idea of having several small and simple
examples that show different API's off :)

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/






More information about the llvm-dev mailing list