[LLVMdev] JIT API example (fibonacci)
Alkis Evlogimenos
alkis at cs.uiuc.edu
Tue Aug 17 19:01:33 PDT 2004
On Tue, 2004-08-17 at 17:47, Chris Lattner wrote:
> 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);
Also instead of this:
SetCondInst* CondInst
= new SetCondInst( Instruction::SetLE,
&ArgX, Two );
BB->getInstList().push_back(CondInst);
you can write it as:
SetCondInst* CondInst
= new SetCondInst( Instruction::SetLE,
&ArgX, Two, "cond", BB);
Ditto for all other instructions.
--
Alkis
More information about the llvm-dev
mailing list