<div dir="ltr"><div>What you've written is;</div><div>Call(foo.weight)</div><div>So the value of foo.weight needs to be loaded from the global address so the value can be passed as a float.</div><div><br></div><div>Were you expecting;</div>Call(&foo.weight)<div>So the address is passed as a pointer to the global structure element.</div><div><br></div><div>Or were you expecting;</div><div>Call(67.2)</div><div>An optimisation that would need to be certain that foo.weight is never over-written.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 11, 2015 at 5:03 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>