Forcing the Interpreter segfaults

Hi everyone !
I am very new to LLVM and intent to use it in a research project.
I have a problem with the interpreter: I have a simple compiler that generates LLVM bitcode, JIT it and execute it, and it works very well.
Now I would like to execute it using the interpreter. And I get a segfault.

Here is the code :

// This code JIT the function and executes it

llvm::InitializeNativeTarget();
llvm::ExecutionEngine * EJ = llvm::ExecutionEngine::create(&nM);
typedef int (*REFunc)(const char *);
union { void * obj; REFunc func; } u;
u.obj = EJ->getPointerToFunction(func);
REFunc jit = u.func;
int ret = jit(“aaa”);
std::cout << std::endl << ret << std::endl;

// This code interprets the function
llvm::initializeCore();
llvm::ExecutionEngine * EI = llvm::EngineBuilder(&M).setEngineKind(llvm::EngineKind::Interpreter).create();
EI->runStaticConstructorsDestructors(false);
std::vectorllvm::GenericValue args;
llvm::GenericValue arg1((void*)“aaabc”);
args.push_back(arg1);
llvm::APInt res = EI->runFunction(func, args).IntVal;
llvm::outs() << res << “\n”;

The first block of code works very well and write the expected result.
The second block segfaults on the EI->runFunction(func, args) call.
I can’t find my mistake. Would somebody help me on this ???

Thank you very much !

Salomon BRYS.

Helps to send to list:

In my case, I am working on a posix regular expression library that uses LLVM to execute a regular expression.
Each regular expression is a very small sets of code and is faster to interpret than to JIT then execute.
I wanted to JIT only when the regular expression is executed more than 20 times.
The benchmarks I have run show that my library is amzingly fast to execute a regular expression (thanks to LLVM) but amzingly slow to compile in JIT.
I need the interpreter to provide a way to execute a regular expression without JITing it, which would be much slower BUT will result in a faster execution IF the regular expression is used only two or three times.

So, is there no way now to execute a LLVM bitcode without JITing ?

If you want to submit patches to update the Interpreter to work with
the modern code, it would certainly be liked, but the Interpreter was
*slow*, it was designed for correctness while the JIT was being
created, not speed.

Hi Salomon,

Hi everyone !
I am very new to LLVM and intent to use it in a research project.
I have a problem with the interpreter: I have a simple compiler that generates
LLVM bitcode, JIT it and execute it, and it works very well.
Now I would like to execute it using the interpreter. And I get a segfault.

please open a bugreport with complete code (so others can try to reproduce
this). Also, did you build LLVM with assertions enabled? Enabling assertions
usually means you get a helpful failure message rather than a segmentation
fault.

Ciao,

Duncan.

Did you try the JIT with -O0 and the local register allocator?
It should emit worse quality code, but much faster. It might still be
faster than the interpreter.

Or you could implement your own interpreter for the regular expression.
A special purpose interpreter (your own for regexes) will always be
faster than a general purpose one (LLVM's).

Best regards,
--Edwin