[LLVMdev] CPP API User-level Question: Returning multiple values

Tony Scudiero tscud at cray.com
Mon Sep 15 05:57:15 PDT 2008


Awesome. Thanks Dan.

    -Tony

Dan Gohman wrote:
> Hi Tony,
>
> I just checked LLVM 2.3 and ReturnInst has these:
>
>    static ReturnInst* Create(Value * const* retVals, unsigned N,
>                              Instruction *InsertBefore)
>
>    static ReturnInst* Create(Value * const* retVals, unsigned N,
>                              BasicBlock *InsertAtEnd)
>
> which are what you're looking for.
>
> In LLVM trunk, MRV-syntax LLVM assembly files and bitcode files
> are auto-upgraded to first-class aggregates in the respective
> readers. However at the C++ API level, clients must be adapted.
>
> Dan
>
> On Sep 12, 2008, at 1:43 PM, Tony Scudiero wrote:
>
>   
>> 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
>>>
>>>       
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>     
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>   




More information about the llvm-dev mailing list