[LLVMdev] MCJIT and Kaleidoscope Tutorial
Dmitri Rubinstein
dmitri.rubinstein at googlemail.com
Tue Jun 4 11:45:28 PDT 2013
Thank you for the hint. Now I am observing a different problem.
I am testing MCJIT with Kaleidoscope examples on x86_64 and ARM (since
JIT does not work on ARM). Kaleidoscope defines printd function in the
host code which is also available to the JIT. Then printd is used to
print double numbers 123.0 and 4.0. Instead of them 1.0 and 0.0 numbers
are output.
I further investigated this and created following example:
-- printd.c --
#include <stdio.h>
double printd(double X)
{
printf("printd: %f\n", X);
return 0;
}
-- print.c --
#include <stdio.h>
extern double printd(double X);
int main(int argc, char **argv)
{
printd(123.0);
printd(4.0);
return 0;
}
I compile printd.c to shared library, which I then load with lli:
> gcc printd.c -fPIC -shared -o printd.so
> clang -Wall -c -emit-llvm -O3 print.c -o print.bc
> lli -use-mcjit -load=./printd.so print.bc
printd: 1.000000
printd: 0.000000
When I put printd implementation into print.c everything works fine, I
get expected numbers. Also everything works fine when I use 'int
printi(int)' instead of 'double printd(double)'. Looks for me like a
linking/HardFP-ABI related problem. This problem does not appear on
x86_64 at all.
Any ideas ?
ARM configuration is QEMU with RaspberryPi Raspbian “wheezy” kernel,
hard float support. LLVM datalayout and triple produced by clang are:
target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:64-n32-S64"
target triple = "armv4t-unknown-linux-gnueabihf"
Best,
Dmitri
Am 04.06.2013 18:10, schrieb Kaylor, Andrew:
> Hi Dmitri,
>
> You're right. The lli code should be cleaned up. As David said, there was a time when the call to invalidate the instruction cache was necessary. It isn't necessary anymore.
>
> -Andy
>
> -----Original Message-----
> From: Dmitri Rubinstein [mailto:dmitri.rubinstein at googlemail.com]
> Sent: Tuesday, June 04, 2013 7:20 AM
> To: David Tweed
> Cc: Kaylor, Andrew; LLVM Dev
> Subject: Re: [LLVMdev] MCJIT and Kaleidoscope Tutorial
>
>
> Am 04.06.2013 16:05, schrieb David Tweed:
>> | I am curious about JMM->invalidInstructionCache(), which I found in
>> | lli.cpp implementation. lli.cpp contains also call finalizeObject(),
>> | I just overlooked it. lli.cpp calls finalizeObject(), which calls
>> | applyPermissions, which in turn calls invalidateInstructionCache. So
>> | why lli.cpp does call JMM->invalidInstructionCache() explicitely again ?
>>
>> My suspicion is it's a historical development; because different
>> architectures do or don't actually require cache invalidation the
>> calls have tended not to be initially put in, then added when other
>> architectures started using the code. When I was doing some cosmetic
>> changes related to that I didn't touch lli because the impression
>> seemed to be that it was very little used these days, so erring on the
>> safe side seemed more important than being completely minimal. In
>> general, nowadays lli is not an example of the cleanest way to use MCJIT.
>
> But then there is no clean example of using MCJIT at all, please correct me if I am wrong. I just did a "git grep MCJIT" in the LLVM git repo, and the only tool using MCJIT is lli. Since Kaleidoscope tutorials are not compatible with MCJIT, there is also no tutorial explaining how to use MCJIT.
>
> Best,
> Dmitri
>
>>
>> Cheers,
>> Dave
>>
>>
>>
>
More information about the llvm-dev
mailing list