[LLVMdev] const indices of extractvalue

Dan Gohman gohman at apple.com
Tue Jul 13 10:22:42 PDT 2010


On Jul 13, 2010, at 7:44 AM, Jianzhou Zhao wrote:

> Hi,
> 
> The 'extractvalue' and 'insertvalue' instructions only allow constant
> indices.  

Yes.

> If I have an array with variable indices,  I need to store
> it into memory, and then load its sub-elements via GEP.

If you have an array with variable indices, it should already be in
memory, so you shouldn't ever have to store it first.

> Why could
> 'extractvalue' not support variable indices like GEP?

The idiom of tossing around whole arrays or structs by value is
very difficult to implement effectively, and it's not the intent
of extractvalue to attempt to support this.

The special case of very small structs (around two elements)
does work reasonably well for modeling functions with multiple
return values and a few other similar things. Dynamic indices
aren't needed for these, and would be very awkward to implement.

> In general, in
> which case should source code be translated into 'extractvalue' , and
> when should frontends use GEP for aggregate data?


Front-ends should put structs and arrays in memory and use GEP. LLVM
will raise parts of them from memory to registers as needed
(scalarrepl, gvn, etc.).

Dan




More information about the llvm-dev mailing list