[LLVMdev] Chatty C++API code generation

Reid Kleckner rnk at google.com
Tue Mar 10 11:39:44 PDT 2015


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.

On Tue, Mar 10, 2015 at 11:33 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/20150310/6e26d1ba/attachment.html>


More information about the llvm-dev mailing list