[llvm-dev] Execution

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] Execution

ORiordan, Martin via llvm-dev
​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
-- 
This email was Anti Virus checked by  Security Gateway.

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Execution

ORiordan, Martin via llvm-dev
What's your example.ll looks like?

2017-06-17 3:19 GMT+08:00 Samaneh Berenjian via llvm-dev <[hidden email]>:
​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
-- 
This email was Anti Virus checked by  Security Gateway.

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev




--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Execution

ORiordan, Martin via llvm-dev
In reply to this post by ORiordan, Martin via llvm-dev
On 16 June 2017 at 12:19, Samaneh Berenjian via llvm-dev
<[hidden email]> wrote:
> 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?

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.
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Execution

ORiordan, Martin via llvm-dev
(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.

On 16 June 2017 at 13:54, Samaneh Berenjian <[hidden email]> wrote:

> Thank you for your kind reply. my IR looks like the following and I have
> gotten it from the code in
> https://ian-bertolacci.github.io/llvm/llvmlite/python/compilers/programming/2016/03/06/LLVMLite_fibonacci.html.
> How can I make it looks like what you said me?
> ; ModuleID = "m_fibonacci_example"
> target triple = "unknown-unknown-unknown"
> target datalayout = ""
>
> define i64 @"main"(i64 %".1")
> {
> fn_fib_entry:
>   %".3" = icmp sle i64 %".1", 1
>   br i1 %".3", label %"fn_fib_entry.if", label %"fn_fib_entry.endif"
> fn_fib_entry.if:
>   ret i64 1
> fn_fib_entry.endif:
>   %".6" = sub i64 %".1", 1
>   %".7" = sub i64 %".1", 2
>   %".8" = call i64 @"main"(i64 %".6")
>   %".9" = call i64 @"main"(i64 %".7")
>   %".10" = add i64 %".8", %".9"
>   ret i64 %".10"
> }
>
> Thank you in advance
>
>
>
>
> On Fri, 06/16/2017 03:50 PM, Tim Northover &lt;[hidden email]&gt;
> wrote:
>
> On 16 June 2017 at 12:19, Samaneh Berenjian via llvm-dev
> <[hidden email]> wrote:
>> 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?
>
> 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.
>
> --
> This email was Anti Virus checked by Security Gateway.
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Execution

ORiordan, Martin via llvm-dev
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


On Fri, 06/16/2017 05:13 PM, Tim Northover &lt;[hidden email]&gt; wrote:
(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.

On 16 June 2017 at 13:54, Samaneh Berenjian " target="_blank"><[hidden email]> wrote:

> Thank you for your kind reply. my IR looks like the following and I have
> gotten it from the code in
> https://ian-bertolacci.github.io/llvm/llvmlite/python/compilers/programming/2016/03/06/LLVMLite_fibonacci.html.
> How can I make it looks like what you said me?
> ; ModuleID = "m_fibonacci_example"
> target triple = "unknown-unknown-unknown"
> target datalayout = ""
>
> define i64 @"main"(i64 %".1")
> {
> fn_fib_entry:
> %".3" = icmp sle i64 %".1", 1
> br i1 %".3", label %"fn_fib_entry.if", label %"fn_fib_entry.endif"
> fn_fib_entry.if:
> ret i64 1
> fn_fib_entry.endif:
> %".6" = sub i64 %".1", 1
> %".7" = sub i64 %".1", 2
> %".8" = call i64 @"main"(i64 %".6")
> %".9" = call i64 @"main"(i64 %".7")
> %".10" = add i64 %".8", %".9"
> ret i64 %".10"
> }
>
> Thank you in advance
>
>
>
>
> On Fri, 06/16/2017 03:50 PM, Tim Northover &lt;[hidden email]&gt;
> wrote:
>
> On 16 June 2017 at 12:19, Samaneh Berenjian via llvm-dev
> " target="_blank"><[hidden email]> wrote:
>> 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?
>
> 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.
>
> --
> This email was Anti Virus checked by Security Gateway.

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Execution

ORiordan, Martin via llvm-dev
On 16 June 2017 at 14:24, Samaneh Berenjian <[hidden email]> wrote:
> 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.

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

combined_module.ll (1K) Download Attachment