<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54774>54774</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            how to add struct parameter of custom function in JIT
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          profdevc
      </td>
    </tr>
</table>

<pre>
    for an code example like:
```
#include <iostream>

struct st{
    int num;
};

void func(struct st &a, int t){
    switch (t)
    {
    case 0:
        a.num++;
        break;
    case 1:
        a.num--;
        break;
    //maybe there are other cases
    default:
        break;
    }
}

int main(){
    return 0;
}
```

after emit it to .ll, there will be a function like
```
define dso_local void @_Z4funcR2sti(%struct.st* nonnull align 4 dereferenceable(4) %0, i32 %1)
```

according to [LLJITWithOptimizingIRTransform.cpp](https://github.com/llvm/llvm-project/blob/main/llvm/examples/OrcV2Examples/LLJITWithOptimizingIRTransform/LLJITWithOptimizingIRTransform.cpp) and [HowToUseLLJIT.cpp](https://github.com/llvm/llvm-project/blob/main/llvm/examples/HowToUseLLJIT/HowToUseLLJIT.cpp), I'd like to build a module and create three ```llvm::function``` corresponding to cases in func, like func_0, func_1 and func_default for given t.  
My idea is give a ```builder.createCall(func)``` in my custom ```llvm::function```
My question are
1. how to get struct type? for ```auto M = parseIRFile("code.ll", *Err, *Ctx);```, how to get struct st from ```M``` which is needed. maybe need to use [StructType](https://llvm.org/doxygen/classllvm_1_1StructType.html)
2. how to set parameter? most of examples I can find, the parameter are all value*, they push it to vector in order, but how to deal with different types in this example. and seems the [createCall](https://llvm.org/doxygen/classllvm_1_1IRBuilderBase.html#ac0a05f15e5416a747e981a9addffcb5b) only reveice value* array.

also, I'm not sure whether my idea is right. In my project, there are many switch cases in serval functions, but like 80/20 Principle, only part of them are called most. I'd like to use the way to generate corresponding functions like [LLJITWithOptimizingIRTransform.cpp](https://github.com/llvm/llvm-project/blob/main/llvm/examples/OrcV2Examples/LLJITWithOptimizingIRTransform/LLJITWithOptimizingIRTransform.cpp) so that they don't need to repeat the same switch again and again, which can speed up the program.  
If the idea is all right, could anyone give an code example for my demand?  
Hope for help
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVstu4zYU_Rp5Q4yghxU7Cy9iZ4JxMYMWadoC3QQUeWWxQ4kqSdnjfn0vrx6OM0E7LdBNDdmmRPI-zzlUaeR5UxnLeMuEkcDgC286DUyrzxDld1FyHyV30U0yXsNtlqtW6B6XR_lOGect8CbK34_T9IsPe-GZ89FqOzxh-FGtZ22Pa8dn0er-Mqbfo1GSVX0romw922BRdsOjbEf7fZTdXhl1J-VFjWvWNDU_v1okuAOWzCmx8cPjEE62DVe-vZ4rMa3PV0_JSPq2kXfvvsFAlD3g1fBzCczXYIFx_JowJOPuslRCxXvtv3L2hlEs4lzNF6UMxWq4arEwr0tmwfe2DfXYvt76qtf0yyuPAUKjPMPLGxZrHdoxpHBSWjNMiFPfvDLtAJ-37GFWqgUmnXnWRnDNqN_RMnn-dRl2P2bOKwq4GLofI4KyO9aatu3RDdfq0LIlVsdChd9WAC814I4l5oj1LRLCSZ6FcTrj4e20hDBWqvYQUoqK7ceP3-2fflG-_r7zqlF_4Mz-8cny1iFFmlh0XVTco6va-86FxlA3D7ihL2NhEEcPWh-nv3edNb-BwPAfSm1K6ntoxrRmpJrD4fdW_Jy9v9z_dSB_u4AixWrwVoa0PpjTk_nJAW36D7O48vP6fowpNGcfZStJEAl1L3ulJWKnMbJH4QkxC4S4DwSxgBIzdY4cYrj53QSzeQq1y1pwnWmnbhKZUC5GKdkN7sLNMwGERil5o-HINha08KCO0DIfI7MIJp_OTEngTDmawlhnxxQ82HiIeMcDLdaDy9tLdBhGc2aid94035TP7Pf3HhwRCmVieJjGrDankOIBgjSSQvpzh2r9QNHPRniPiz6hRN-zjlsH-8cHRUyJsixoPXE4C8VAgr23dhzt_JcQPArD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