Chatty C++API code generation

Hi all,

when I have c code like
--- c code -------------
struct stest { /* deklariert den Strukturtyp person */
    int age;
    float weight;
} foo={44,67.2}; /* deklariert Variable des Typs person */

int main() {

   callAFunction(foo.weight);

Yes, the C++ API LLVM IR “backend” is pretty verbose. It doesn’t use IRBuilder, which is the preferred IR generation interface these days.

However, the “load” in your example is required. All LLVM based compilers model user variables as objects in memory. In order to pass a variable to a function, you have to load it from memory first.

What you’ve written is;
Call(foo.weight)
So the value of foo.weight needs to be loaded from the global address so the value can be passed as a float.

Were you expecting;
Call(&foo.weight)So the address is passed as a pointer to the global structure element.

Or were you expecting;
Call(67.2)
An optimisation that would need to be certain that foo.weight is never over-written.

Jeremy,
you are totally right:
I did Call(foo.weight) and was expecting Call(&foo.weight).

Thanks!

Alex

Jeremy Lakeman wrote: