[LLVMdev] Extracting a value from an union

Frank Winter fwinter at jlab.org
Wed Oct 23 08:22:32 PDT 2013


I cannot figure out the right way to extract values from an
array of unions. Unions are not directly supported and this
seems to complicate things.

Background:
I am call a function returned by the JIT execution machine
and pass it 1 argument, namely the base address of an array
of unions which contain the real arguments.

The data structure is set up from C like:

std::array<union{int,float*}> arguments(5);

The sequence of occurences of 'int' and 'float*' is encoded
in a vector<llvm::Type*>:

i32
i32
float*
float*
float*

Right now I am trying this (this is the jitted function):

define void @main([8 x i8]* %arg_ptr) {
entrypoint:
   %0 = getelementptr [8 x i8]* %arg_ptr, i32 0
   %1 = getelementptr [8 x i8]* %arg_ptr, i32 1
   %2 = getelementptr [8 x i8]* %arg_ptr, i32 2
   %3 = getelementptr [8 x i8]* %arg_ptr, i32 3
   %4 = getelementptr [8 x i8]* %arg_ptr, i32 4
}

First of all, is the functions' signature correct (assuming
pointers are 8 bytes)?

How do I get the first 'i32' out of the [8 x i8] stored in %0?

Do I need to cast the array [8 x i8] first to a pointer i32*,
then create another GEP to its first element?

Frank




More information about the llvm-dev mailing list