Tony Scudiero
2008-Sep-12 16:40 UTC
[LLVMdev] CPP API User-level Question: Returning multiple values
Greetings, I'm working on getting our compiler's interface to LLVM to mimic the way the LLVM-GCC inserts instructions to generate AMD64 ABI compliant code. I'm trying to create ret i64 %mrv, double %double_mrv37 which is basically what LLVM-GCC puts out. However if I use lcc -march=cpp to get the API code I need it has the following line: ReturnInst::Create(int64_t93, label_return); with no reference to the double. I also can't find anything in the doxygen docs for a version of ReturnInst::Create( ) that takes two values for returning, nor could I find anything by generating an intentionally bad call and letting my gen-compiler list the possible ReturnInst which it knows about. Do I have to create the ReturnInst in a different way to do this? Any guidance for how to do this from within the CPP API would be greatly appreciated. Thanks!! -Tony Scudiero
heisenbug
2008-Sep-12 17:44 UTC
[LLVMdev] CPP API User-level Question: Returning multiple values
On Sep 12, 6:40 pm, Tony Scudiero <ts... at cray.com> wrote:> Greetings, > I'm working on getting our compiler's interface to LLVM to mimic the > way the LLVM-GCC inserts instructions to generate AMD64 ABI compliant > code. I'm trying to create > > ret i64 %mrv, double %double_mrv37 > > which is basically what LLVM-GCC puts out. However if I use lcc > -march=cpp to get the API code I need it has the following line: > > ReturnInst::Create(int64_t93, label_return); > > with no reference to the double. I also can't find anything in the > doxygen docs for a version of ReturnInst::Create( ) that takes two > values for returning, nor could I find anything by generating an > intentionally bad call and letting my gen-compiler list the possible > ReturnInst which it knows about. Do I have to create the ReturnInst in a > different way to do this? Any guidance for how to do this from within > the CPP API would be greatly appreciated. Thanks!!Hi Tony, this is probably a bug in the CPP "back end". You have exercised an as of yet untriggered condition and CPP happens to output uncompilable code. Just go to the CppEmitter, modify each string literal the contains "ReturnInst::Create" with a unique comment and rebuild. On your next attempt to compile using llc you will get a nice hint which line in teh emitter is the guilty one. Cheers, Gabor> > -Tony Scudiero > > _______________________________________________ > LLVM Developers mailing list > LLVM... at cs.uiuc.edu http://llvm.cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Dan Gohman
2008-Sep-12 18:46 UTC
[LLVMdev] CPP API User-level Question: Returning multiple values
On Sep 12, 2008, at 9:40 AM, Tony Scudiero wrote:> Greetings,Hi Tony, This is an area that's undergone some changes recently. The LLVM 2.3 multiple-return-value (MRV) syntax has been replaced by the first-class aggregates syntax in SVN trunk.> > I'm working on getting our compiler's interface to LLVM to mimic > the > way the LLVM-GCC inserts instructions to generate AMD64 ABI compliant > code. I'm trying to create > > ret i64 %mrv, double %double_mrv37This is LLVM 2.3 MRV syntax.> > > which is basically what LLVM-GCC puts out. However if I use lcc > -march=cpp to get the API code I need it has the following line: > > ReturnInst::Create(int64_t93, label_return); > > with no reference to the double. I also can't find anything in the > doxygen docs for a version of ReturnInst::Create( ) that takes two > values for returning, nor could I find anything by generating an > intentionally bad call and letting my gen-compiler list the possible > ReturnInst which it knows about. Do I have to create the ReturnInst > in a > different way to do this? Any guidance for how to do this from within > the CPP API would be greatly appreciated. Thanks!!I don't know the details about the LLVM 2.3 interface offhand. I believe there's a form of ReturnInst::Create which you can pass multiple values, probably an array of Value*. I can tell you about how to do this with the first-class aggregates approach in svn trunk though. With first-class aggregates, it's necessary to build up the aggregate return value one piece at a time. The LLVM syntax looks like this: define { i64, double } @foo(i64 %x, double %y) nounwind { %a = insertvalue { i64, double } undef, i64 %x, 0 %b = insertvalue { i64, double } %a, double %y, 1 ret { i64, double } %b } See the LangRef.html for details on the insertvalue instruction. The -march=cpp backend in SVN trunk supports this too. Also in svn trunk, if you're using the IRBuilder interface you can use the CreateAggregateRet method, which takes care of creating the InsertValueInsts for you. Dan
Tony Scudiero
2008-Sep-12 20:43 UTC
[LLVMdev] CPP API User-level Question: Returning multiple values
Dan, Thanks for the info. Unfortunately for the time being we are using (for the most part) the 2.3 release (with a couple of patches that Dave Greene has applied). The first-class aggregates is one of the things we don't yet have in the LLVM we're working with. I'll look again to see if there's a ReturnInst::Create( ) which I can pass an array of llvm::Value *'s to, but I don't recall having seen one. Unfortunately it's all going to change once we do bring our LLVM up to date with changes made to trunk since the LLVM2.3 release, but do we need to get it working with the LLVM we have for the time being - which means using the 2.3 MRV syntax for the time being. Out of curiosity: does the MRV syntax will still work with first-class aggregates? Thanks! -Tony Scudiero Dan Gohman wrote:> On Sep 12, 2008, at 9:40 AM, Tony Scudiero wrote: > > >> Greetings, >> > > Hi Tony, > > This is an area that's undergone some changes recently. The LLVM 2.3 > multiple-return-value (MRV) syntax has been replaced by the > first-class aggregates syntax in SVN trunk. > > >> I'm working on getting our compiler's interface to LLVM to mimic >> the >> way the LLVM-GCC inserts instructions to generate AMD64 ABI compliant >> code. I'm trying to create >> >> ret i64 %mrv, double %double_mrv37 >> > > This is LLVM 2.3 MRV syntax. > > >> which is basically what LLVM-GCC puts out. However if I use lcc >> -march=cpp to get the API code I need it has the following line: >> >> ReturnInst::Create(int64_t93, label_return); >> >> with no reference to the double. I also can't find anything in the >> doxygen docs for a version of ReturnInst::Create( ) that takes two >> values for returning, nor could I find anything by generating an >> intentionally bad call and letting my gen-compiler list the possible >> ReturnInst which it knows about. Do I have to create the ReturnInst >> in a >> different way to do this? Any guidance for how to do this from within >> the CPP API would be greatly appreciated. Thanks!! >> > > > I don't know the details about the LLVM 2.3 interface offhand. > I believe there's a form of ReturnInst::Create which you can > pass multiple values, probably an array of Value*. > > I can tell you about how to do this with the first-class > aggregates approach in svn trunk though. > > With first-class aggregates, it's necessary to build up the > aggregate return value one piece at a time. The LLVM syntax looks > like this: > > define { i64, double } @foo(i64 %x, double %y) nounwind { > %a = insertvalue { i64, double } undef, i64 %x, 0 > %b = insertvalue { i64, double } %a, double %y, 1 > ret { i64, double } %b > } > > See the LangRef.html for details on the insertvalue instruction. > The -march=cpp backend in SVN trunk supports this too. > > Also in svn trunk, if you're using the IRBuilder interface > you can use the CreateAggregateRet method, which takes care of > creating the InsertValueInsts for you. > > Dan > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Maybe Matching Threads
- [LLVMdev] CPP API User-level Question: Returning multiple values
- [LLVMdev] CPP API User-level Question: Returning multiple values
- [LLVMdev] CPP API User-level Question: Returning multiple values
- [LLVMdev] Plans considering first class structs and multiple return values
- [LLVMdev] Plans considering first class structs and multiple return values