Danny
2008-Jan-04 02:14 UTC
[LLVMdev] Calling functions across modules. And those pesky vectors!
Before I get started with more questions, thanks for the prompt reply on my last set question, that was much appreciated. First, I found references to lazy inling and optimizations for calling functions across modules, but I can't figure out how to do that. If I just take a Function* that I got out of one module and call it from the other, it doesn't work. What's the general method for dealing with interactions between modules? Up until this point, everything I've done has been within one module. Second, I was under the impression that vector types were fairly well, but I can't seem to get a simple function which takes in and returns vectors to work properly. And I don't understand the error. I made a simple function which was just supposed to multiply two 3 component float vectors and return the result: //Snip on: VectorType *vType = VectorType::get(Type::FloatTy, 3); std::vector<const Type*> Vectors(2, vType); FunctionType *mul_type = FunctionType::get(vType, Vectors, false); Function* mul = new Function(mul_type, Function::ExternalLinkage, "mul", mod); mul->setCallingConv(CallingConv::C); Function::arg_iterator args = mul->arg_begin(); Value* x = args++; x->setName("x"); When I run getPointerToFunction I get an abort trap with the message: Return operand #1 has unhandled type f32 When I print out the LLVM IR that was produced I get this: ; ModuleID = 'test' define <3 x float> @mul(<3 x float> %x, <3 x float> %y) { entry: %result = mul <3 x float> %x, %y ; <<3 x float>> [#uses=1] ret <3 x float> %result } Which seems pretty reasonable to me. Can anyone help me understand what's going on? Thanks a lot! -danny
Gordon Henriksen
2008-Jan-04 14:57 UTC
[LLVMdev] Calling functions across modules. And those pesky vectors!
On 2008-01-03, at 21:14, Danny wrote:> Before I get started with more questions, thanks for the prompt > reply on my last set question, that was much appreciated. > > First, I found references to lazy inling and optimizations for > calling functions across modules, but I can't figure out how to do > that. If I just take a Function* that I got out of one module and > call it from the other, it doesn't work. What's the general method > for dealing with interactions between modules? Up until this point, > everything I've done has been within one module.One module should contain a declaration of the function (with no body), and the other should contain the definition (with a body). Generally speaking, the modules then need to be linked together (i.e., become one module) before the declaration can be resolved to the definition. This can happen either before or after compilation. In a JIT context, you can skip linking. Instead, just call addModuleProvider for as many additional modules as you have.> Second, I was under the impression that vector types were fairly > well, but I can't seem to get a simple function which takes in and > returns vectors to work properly. And I don't understand the error. > I made a simple function which was just supposed to multiply two 3 > component float vectors and return the result:You may be treading on thin ice, here. There used to be a requirement that vectors have power-of-two widths. File bugs. :) — Gordon
Chris Lattner
2008-Jan-04 17:55 UTC
[LLVMdev] Calling functions across modules. And those pesky vectors!
On Thu, 3 Jan 2008, Danny wrote:> Second, I was under the impression that vector types were fairly well, > but I can't seem to get a simple function which takes in and returns > vectors to work properly. And I don't understand the error. I made a > simple function which was just supposed to multiply two 3 component > float vectors and return the result:Non-power-of-two vectors are a very new feature and are not fully supported. You'll get best results if you stick with vectors of legal size for your hardware, e.g. 4 x float for sse or altivec. -Chris -- http://nondot.org/sabre/ http://llvm.org/
Christopher Lamb
2008-Jan-04 19:40 UTC
[LLVMdev] Calling functions across modules. And those pesky vectors!
On Jan 3, 2008, at 6:14 PM, Danny wrote:> Before I get started with more questions, thanks for the prompt > reply on > my last set question, that was much appreciated. > > First, I found references to lazy inling and optimizations for calling > functions across modules, but I can't figure out how to do that. If I > just take a Function* that I got out of one module and call it from > the > other, it doesn't work. What's the general method for dealing with > interactions between modules? Up until this point, everything I've > done > has been within one module. > > > Second, I was under the impression that vector types were fairly well, > but I can't seem to get a simple function which takes in and returns > vectors to work properly. And I don't understand the error. I made a > simple function which was just supposed to multiply two 3 component > float vectors and return the result: > > //Snip on: > VectorType *vType = VectorType::get(Type::FloatTy, 3); > > std::vector<const Type*> Vectors(2, vType); > FunctionType *mul_type = FunctionType::get(vType, Vectors, > false); > Function* mul = new Function(mul_type, > Function::ExternalLinkage, "mul", mod); > mul->setCallingConv(CallingConv::C); > > Function::arg_iterator args = mul->arg_begin(); > Value* x = args++; > x->setName("x"); > > When I run getPointerToFunction I get an abort trap with the message: > Return operand #1 has unhandled type f32 > > When I print out the LLVM IR that was produced I get this: > ; ModuleID = 'test' > > define <3 x float> @mul(<3 x float> %x, <3 x float> %y) { > entry: > %result = mul <3 x float> %x, %y ; <<3 x > float>> > [#uses=1] > ret <3 x float> %result > } > > Which seems pretty reasonable to me. > > Can anyone help me understand what's going on?CodeGen for non-power-of-2 vector lengths is not working for any target yet, I belive. Try the same thing with a 4-element vector and it'll probably work. -- Christopher Lamb -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080104/131c5e2c/attachment.html>
Nick Lewycky
2008-Jan-05 05:52 UTC
[LLVMdev] Calling functions across modules. And those pesky vectors!
Danny wrote: I made a> simple function which was just supposed to multiply two 3 component > float vectors and return the result:"Vectors must have a power of two length (1, 2, 4, 8, 16 ...)." - http://llvm.org/docs/LangRef.html#t_vector> //Snip on: > VectorType *vType = VectorType::get(Type::FloatTy, 3);Nick
Arnold Schwaighofer
2008-Jan-05 09:00 UTC
[LLVMdev] Tailcall optimization in jit stopped working
> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of- > Mon-20071231/056781.html > > Can you see if it's working for you now?Thanks Evan, yes that does the trick.
Evan Cheng
2008-Jan-07 18:46 UTC
[LLVMdev] Calling functions across modules. And those pesky vectors!
There is on going work to allow non-power of 2 vectors. Perhaps others can say more of the current status. Evan On Jan 4, 2008, at 9:52 PM, Nick Lewycky wrote:> Danny wrote: > I made a >> simple function which was just supposed to multiply two 3 component >> float vectors and return the result: > > "Vectors must have a power of two length (1, 2, 4, 8, 16 ...)." > - http://llvm.org/docs/LangRef.html#t_vector > >> //Snip on: >> VectorType *vType = VectorType::get(Type::FloatTy, 3); > > Nick > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Jon Harrop
2008-Jan-07 22:17 UTC
[LLVMdev] Calling functions across modules. And those pesky vectors!
On Friday 04 January 2008 17:55:34 Chris Lattner wrote:> On Thu, 3 Jan 2008, Danny wrote: > > Second, I was under the impression that vector types were fairly well, > > but I can't seem to get a simple function which takes in and returns > > vectors to work properly. And I don't understand the error. I made a > > simple function which was just supposed to multiply two 3 component > > float vectors and return the result: > > Non-power-of-two vectors are a very new feature and are not fully > supported. You'll get best results if you stick with vectors of legal > size for your hardware, e.g. 4 x float for sse or altivec.Are you planning to support arbitrary-length vectors then? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e