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

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

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

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:

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

Awesome. Thanks Dan.

    -Tony

Dan Gohman wrote: