[LLVMdev] Chatty C++API code generation

Jeremy Lakeman Jeremy.Lakeman at gmail.com
Tue Mar 10 19:12:17 PDT 2015


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.


On Wed, Mar 11, 2015 at 5:03 AM, Alexander Poddey <alexander.poddey at gmx.net>
wrote:

> 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);
>
> ------------------------
>
> The generated c++API code to me seems to be too chatty in the sense that
> the foo.weight's data is copied to a local variable using a load
> instruction.
> The call instruction is then using the local copy.
>
> --- API code ---------------
> ...
> std::vector<Constant*> const_ptr_113_indices;
> const_ptr_113_indices.push_back(const_int32_103);
> const_ptr_113_indices.push_back(const_int32_104);
> Constant* const_ptr_113 = ConstantExpr::getGetElementPtr(gvar_struct_adam,
> const_ptr_113_indices);
>
> //here we have const_ptr_113; why not use it in theCallInst?
>
>  LoadInst* float_130 = new LoadInst(const_ptr_113, "", false,
> label_entry_121);
>  float_130->setAlignment(4);
>
>  CallInst* float_call = CallInst::Create(func__Z4fib3f, float_130, "call",
> label_entry_121);
> ------------------------------------------------
>
>
> To me, this ll code seems to relate to something like
> int main() {
>    float localfloat=foo.weight;
>    callAFunction(localfloat);
>
> This is distinct from the original code...
>
> Do I have a missunderstanding?
> Thanks
> Alexander
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150311/3450e9a4/attachment.html>


More information about the llvm-dev mailing list