is this code really JITed and/or optimized ? ..

Hi all,

(thanks to Reid, who gave nice advice) the fibonacci function code
works now. Please find attached file.

but... the performance is adequate, say, for byte-code
interpretation mode and not for optimized JITing.
fibonacci function of 35 from attached file is more
then 100 times slower then the following code compiled
with "gcc -O2" :

fibonacci.cpp (6.13 KB)

If it's that slow, you're probably getting the interpreter instead of the
JIT. Try adding -print-machineinstr to the command line, or -debug, and
see what happens. If you're not getting the JIT, try stepping through the
LLVM program to see where it makes the execution engine and decides which
one to use...

-Chris

Valery,

The line in the file HowToUseJIT.cpp that reads:
   ExecutionEngine* EE = ExecutionEngine::create( MP, true );

should be
   ExecutionEngine* EE = ExecutionEngine::create( MP, false);

The second parameter is "forceInterpreter" which will always cause interpretation. I left it that way because that's what you had in your original submission. Thought you wanted to compare them.

Anyway, the above change will allow JIT to happen.

Reid.

Chris Lattner wrote:

If it's that slow, you're probably getting the interpreter instead of the
JIT. Try adding -print-machineinstr to the command line, or -debug, and
see what happens. If you're not getting the JIT, try stepping through the
LLVM program to see where it makes the execution engine and decides which
one to use...

(thanks for quick reply)

hm, here is the part of my code starting LLVM function:

///////////////////////////
  ExistingModuleProvider* MP = new ExistingModuleProvider(M);
  ExecutionEngine* EE = ExecutionEngine::create( MP, true );

  // Call the `foo' function with no arguments:
  std::vector<GenericValue> noargs;
  GenericValue gv = EE->runFunction(FooF, noargs);
///////////////////////////

for LLVM developers no debuging should be needed to make
quick and right diagnosis :slight_smile:

hm, here is the part of my code starting LLVM function:

///////////////////////////
  ExistingModuleProvider* MP = new ExistingModuleProvider(M);
  ExecutionEngine* EE = ExecutionEngine::create( MP, true );

As Reid pointed out, changing true to false will get it to work.

  // Call the `foo' function with no arguments:
  std::vector<GenericValue> noargs;
  GenericValue gv = EE->runFunction(FooF, noargs);
///////////////////////////

for LLVM developers no debuging should be needed to make
quick and right diagnosis :slight_smile:

Sure, but part of our goal is to get you to learn more about how stuff
works too :slight_smile:

-Chris

> ExecutionEngine* EE = ExecutionEngine::create( MP, true );
As Reid pointed out, changing true to false will get it to work.

hm, well, "false" causes Segmentation fault.

> for LLVM developers no debuging should be needed to make
> quick and right diagnosis :slight_smile:

Sure, but part of our goal is to get you to learn more about how stuff
works too :slight_smile:

LOL, i deleted few lines from my previous mail before send i.r.t. this your
idea, which is well-known to me :slight_smile:

Actually my LLVM is compiled with no debug info. Newly compiled LLVM
with debug support will be after ~45min :-/

> ExecutionEngine* EE = ExecutionEngine::create( MP, true );

As Reid pointed out, changing true to false will get it to work.

as I've posted already, I got Segmentation Fault.
Now, i have re-compiled LLVM with debug support.

The evaluation is broken at line 78 in file:
lib/ExecutionEngine/JIT/JIT.cpp

The assertion

    assert(ArgValues.size() == 1);

fails. But what's wrong? My function has type

int FooF(void);

so ArgValues should have size 0, right?

BTW, the code of runFunction is quite unclear, indeed,
for some reason cases ArgValues==3 and ArgValues==1
are specially considered... I looked in JIT.h for
more description on interface -- quite ascetic info,
nothing interesting.

Anyway, few lines of documentation could make life easier
for other guys too.

Thanks in advance,

> > ExecutionEngine* EE = ExecutionEngine::create( MP, true );
> As Reid pointed out, changing true to false will get it to work.

as I've posted already, I got Segmentation Fault.
Now, i have re-compiled LLVM with debug support.

The evaluation is broken at line 78 in file:
lib/ExecutionEngine/JIT/JIT.cpp

The assertion

    assert(ArgValues.size() == 1);

fails. But what's wrong? My function has type
int FooF(void);
so ArgValues should have size 0, right?

Yes, you're right.

BTW, the code of runFunction is quite unclear, indeed, for some reason
cases ArgValues==3 and ArgValues==1 are specially considered... I looked
in JIT.h for more description on interface -- quite ascetic info,
nothing interesting. Anyway, few lines of documentation could make life
easier for other guys too.

If you look at the 3 lines above the assert that is failing, you'll see
this:

    // FIXME: This code should handle a couple of common cases efficiently, but
    // it should also implement the general case by code-gening a new anonymous
    // nullary function to call.

Basically it's saying that we only support one argument functions that
take an integer right now. This is a bug/suboptimality, hence the FIXME.

There are several different ways to fix the problem, as hinted at by the
comment. In the short term, adding something like this:

  } else if (ArgValues.empty()) {
    void (*PF)() = (void(*)())getPointerToFunction(F);
    assert(PF && "Pointer to fn's code was null after getPointerToFunction");
    PF();

before the "else" case, should fix the issue for you. That code is
basically only smart enough to run 'main', but could be enhanced by
someone interested in it to handle the general case.

-Chris

ick! Is there a bugzilla on this?

Reid.

ick! Is there a bugzilla on this?

Nope, feel free.

-Chris