[LLVMdev] Chatty C++API code generation

Alexander Poddey alexander.poddey at gmx.net
Tue Mar 10 11:33:57 PDT 2015


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





More information about the llvm-dev mailing list