<div dir="ltr"><div>Yes, the C++ API LLVM IR "backend" is pretty verbose. It doesn't use IRBuilder, which is the preferred IR generation interface these days.</div><div><br></div><div>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.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 10, 2015 at 11:33 AM, Alexander Poddey <span dir="ltr"><<a href="mailto:alexander.poddey@gmx.net" target="_blank">alexander.poddey@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
when I have c code like<br>
--- c code -------------<br>
 struct stest {         /* deklariert den Strukturtyp person */<br>
    int   age;<br>
    float weight;<br>
 } foo={44,67.2};            /* deklariert Variable des Typs person */<br>
<br>
<br>
<br>
int main() {<br>
<br>
   callAFunction(foo.weight);<br>
<br>
------------------------<br>
<br>
The generated c++API code to me seems to be too chatty in the sense that<br>
the foo.weight's data is copied to a local variable using a load<br>
instruction.<br>
The call instruction is then using the local copy.<br>
<br>
--- API code ---------------<br>
...<br>
std::vector<Constant*> const_ptr_113_indices;<br>
const_ptr_113_indices.push_back(const_int32_103);<br>
const_ptr_113_indices.push_back(const_int32_104);<br>
Constant* const_ptr_113 = ConstantExpr::getGetElementPtr(gvar_struct_adam,<br>
const_ptr_113_indices);<br>
<br>
//here we have const_ptr_113; why not use it in theCallInst?<br>
<br>
 LoadInst* float_130 = new LoadInst(const_ptr_113, "", false,<br>
label_entry_121);<br>
 float_130->setAlignment(4);<br>
<br>
 CallInst* float_call = CallInst::Create(func__Z4fib3f, float_130, "call",<br>
label_entry_121);<br>
------------------------------------------------<br>
<br>
<br>
To me, this ll code seems to relate to something like<br>
int main() {<br>
   float localfloat=foo.weight;<br>
   callAFunction(localfloat);<br>
<br>
This is distinct from the original code...<br>
<br>
Do I have a missunderstanding?<br>
Thanks<br>
Alexander<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>