[LLVMdev] How to pass an array to a function using GenericValue

Alan Garny agarny at hellix.com
Thu Jan 12 15:30:06 PST 2012


> >>> Yes, it was the entire LLVM assembly code that I generated. However,
> >>> I have now prepended targetdata to the code I generate (using
> >>> executionEngine->getTargetData()->getStringRepresentation()), but to
> >>> executionEngine->no
> >>> avail. I still get the exact same result...?!
> >>
> >> What is the string you prepended?  If the execution engine thinks the
> > target is
> >> different to what it is then prepending the execution engine's notion
> >> of
> > target
> >> isn't going to help.
> >
> > I currently prepend:
> >
> >     target datalayout =
> > "E-p:64:64:64-S0-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32
> > -f64:6
> > 4:64-v64:64:64-v128:128:128-a0:0:64"
> 
> well, for example "E" means big endian ("e" would mean little endian), so
> probably this is not what you want (are you on x86?).
> 
> > Otherwise, and as I said, I am new to LLVM, but... how could the
> > execution engine return a target which is different than what it is?
> 
> I guess you mean it should use the characteristics of the machine you are
> running the code on by default.  Actually I thought it did nowadays (in
the bad
> old days it would assume sparc or something like that), but I guess I was
> mistaken.  It looks like you need to say explicitly what kind of machine
you will
> run the code on.

Ok, I have solved my problem and I have you to thank for mentioning the
target data layout. This indirectly pointed me in the right direction.

Basically, the issue was that I was aiming at creating a JIT execution
engine, BUT I had forgotten to call InitializeNativeTarget()! Now that I
have added that call, everything's fine. Doh! I have checked the target data
layout and indeed, it refers to little endian, as expected. Talking of the
target data layout, I don't actually need to have it in the LLVM assembly
code I generate since it's (obviously) information that is part of my JIT
execution engine.

Anyway, everything works fine now. I just need to figure out a way to avoid
calling executionEngine->runFunction() and, instead, use
executionEngine->getPointerToFunction() and then call the function
'directly'. (Indeed, I will need to call that function thousands of times,
so I cannot afford the overhead associated with
executionEngine->runFunction().) Right now, I have something like

	1	void (*func)(double *) = reinterpret_cast<void (*)(double
*)>((intptr_t) executionEngine->getPointerToFunction(function));
	2	func(data);

but line 2 causes my program to crash. Ok, I will have a look at this
tomorrow. In the meantime, thanks again for your help!

Alan




More information about the llvm-dev mailing list