Execution

​Hello all,

I have written a code in llvmlite. Using command numba --dump-llvm example.py > example.ll I can have .ll file. However, using lli example.ll, I am stopped with error: ‘main’ function not found in module. Is there anyway at which it can be executed using lli?
Thank you in advance

Best

What’s your example.ll looks like?

By default lli looks for a function named @main since that's the
traditional C and C++ entry point (amongst others these days). You can
override that and tell it to execute an arbitrary function with the
"-entry-function" argument. Probably wise to make sure the prototype
matches main though (i.e. return and int and take either northing or
an argc, argv pair).

Cheers.

Tim.

(Adding llvm-dev back to the thread in case anyone else comes along
later with the same problem).

Your problem now is this prototype:

define i64 @"main"(i64 %".1")

That's almost certainly not how main is called on your system
(typically it has to be "i32 @main(i32, i8**)" or "i32 @main()" though
odder platforms will differ.

What value do you expect %.1 to have on entry? What do you expect to
happen to the value returned?

I suspect what you really want is to call your function "@fib" and
write a separate wrapper-function @main that calls @fib with sensible
arguments and maybe prints out the result afterwards. You could write
this in C and let Clang give you the IR you need. For example to take
the input as a command-line argument:

#include <stdio.h>
#include <stdlib.h>
long long fib(long long);
int main(int argc, char *argv) {
  printf("%lld\n", fib(atoi(argv[1])));
}

Clang (when I run "clang -Os -S -o- -emit-llvm file.c") tells me the
IR for this is:

@.str = private unnamed_addr constant [6 x i8] c"%lld\0A\00", align 1
define i32 @main(i32, i8** nocapture readonly) {
  %3 = getelementptr inbounds i8*, i8** %1, i64 1
  %4 = load i8*, i8** %3, align 8
  %5 = tail call i32 @atoi(i8* %4)
  %6 = sext i32 %5 to i64
  %7 = tail call i64 @fib(i64 %6)
  %8 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6
x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %7)
  ret i32 0
}
declare i32 @printf(i8* nocapture readonly, ...)
declare i32 @atoi(i8* nocapture)

Put that into a module with your @fib definition and you should be
able to run lli on it:

$ lli combined_module.ll 12
233
$

Cheers.

Tim.

Thank you for your reply. The problem is that I have a python code and not all of the functions of that are convertible to c code. Moreover, may I see your combined_module.ll file ?Thank you

Thank you for your reply. The problem is that I have a python code and not
all of the functions of that are convertible to c code.

I'm afraid I don't understand how this is a problem. You need one
specific @main wrapper function to be able to run the IR you're
producing. It just happens that the simplest way to get that is
probably to compile the corresponding C, you could write it entirely
by hand if you were feeling brave.

Moreover, may I see your combined_module.ll file ?Thank you

Sure, it should be attached to this message. It's just the @main I
showed together with your function renamed to @fib.

Cheers.

Tim.

combined_module.ll (1002 Bytes)