GEPping GEPs and first-class structs

As I understand it, first-class structs will allow structs to be passed as
function arguments and returned as results (i.e. multiple return values)
instead of passing pointers to structs. However, the GEP instruction only
handles pointer types. So I do not understand how you will be able to extract
the fields of a struct when it is received as a value type.

Will the GEP instruction be altered so that it can be applied to structs
directly?

No, see:
http://llvm.org/docs/LangRef.html#i_extractvalue

Andrew

Use the extractvalue instruction.

Dan

As I understand it, first-class structs will allow structs to be passed as

first-class structs already exist. :slight_smile:

function arguments and returned as results (i.e. multiple return values)
instead of passing pointers to structs. However, the GEP instruction only
handles pointer types. So I do not understand how you will be able to extract
the fields of a struct when it is received as a value type.

Use the extractvalue instruction.

Will the GEP instruction be altered so that it can be applied to structs
directly?

No.

-Chris

You can't take the address of a register, much less an element thereof. extractvalue and insertvalue are the instructions to manipulate aggregate registers.

http://llvm.org/docs/LangRef.html#aggregateops

— Gordon

Hi Jon, check out

http://llvm.org/docs/LangRef.html#aggregateops

Ciao,

Duncan.

Wonderful, thank you. I missed this because it wasn't in the C and OCaml
bindings in LLVM 2.4...

Hmm, I cannot get them to work. I suspect the problem is somewhere between
OCaml and their implementation within LLVM because I am not even seeing the
instructions when I visualize my function.

I have augmented "bindings/ocaml/llvm/llvm.ml*", "include/llvm-c/Core.h"
and "lib/VMCore/Core.cpp" with functions to handle InsertValue and
ExtractValue. Any ideas?

Maybe I should leave this until 2.5...