<div dir="ltr"><div>This is an interesting approach, but in general I am trying to avoid function calls with additional code but paste the code into another function.</div><div>Or maybe I didn't get the exact goal of ifunc.<br></div><div>And as I understood Johannes it should be possible to use LLVM IR Linker (in the LLVM IR pass???), then inline the code and optimize everything as one function. Then any dynamic resolving of shouldn't be needed.<br></div><div><br></div><div>Thanks,</div><div>Przemek<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 9, 2021 at 3:08 PM Blower, Melanie I <<a href="mailto:melanie.blower@intel.com">melanie.blower@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div style="overflow-wrap: break-word;" lang="EN-US">
<div class="gmail-m_2915839367162014817WordSection1">
<p class="MsoNormal">How about using ifunc?  The linker calls a resolver function which returns the address of which function to call. The callsite is fixed up with the resolved address as the program is loaded.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Some info here, <a href="https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Function-Attributes.html#index-g_t_0040code_007bifunc_007d-function-attribute-3095" target="_blank">
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Function-Attributes.html#index-g_t_0040code_007bifunc_007d-function-attribute-3095</a>
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-color:currentcolor currentcolor currentcolor blue;border-style:none none none solid;border-width:medium medium medium 1.5pt;padding:0in 0in 0in 4pt">
<div>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> <b>On Behalf Of
</b>Przemyslaw Ossowski via llvm-dev<br>
<b>Sent:</b> Wednesday, June 9, 2021 9:01 AM<br>
<b>To:</b> Johannes Doerfert <<a href="mailto:johannesdoerfert@gmail.com" target="_blank">johannesdoerfert@gmail.com</a>><br>
<b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [llvm-dev] Adding instructions in pass directly from string containing IR<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">but when I went into details I'm wondering if using linker in a simple pass is possible.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Usually passes are executed per module.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Is it possible to use linker and later replace the original module with a newly linked module in simple pass?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Module is passed by reference to runOnModule, so probably it should be possible...<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Przemek<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Tue, Jun 8, 2021 at 6:01 PM Johannes Doerfert <<a href="mailto:johannesdoerfert@gmail.com" target="_blank">johannesdoerfert@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<p class="MsoNormal">If you insert a call prior to the inliner and mark it with the<br>
`alwaysinline` attribute, it will be inlined for sure.<br>
<br>
Reduces your problem to insert a call to a function :)<br>
<br>
~ Johannes<br>
<br>
<br>
On 6/7/21 10:51 AM, Przemyslaw Ossowski wrote:<br>
> Thank you Johannes for your suggestion.<br>
><br>
> In case a call to the function which would contain the code I would like to<br>
> paste is inserted into another function, then is it still possible to<br>
> simply inline the code?<br>
> I would like to avoid calling the function with the "pasted" code. I assume<br>
> there is a pass which inlines functions which should be executed later.<br>
><br>
> Thanks,<br>
> Przemek<br>
><br>
><br>
> On Wed, Jun 2, 2021 at 4:13 AM Johannes Doerfert <<a href="mailto:johannesdoerfert@gmail.com" target="_blank">johannesdoerfert@gmail.com</a>><br>
> wrote:<br>
><br>
>> Hi Przemek,<br>
>><br>
>> I doubt that such functionality exists right now. The main<br>
>> problem I see is the name matching to embed it with other code.<br>
>> If the new code is not connected, I'd recommend the pass to<br>
>> read in an IR file with a function in it, link it into the module,<br>
>> and insert a call wherever you want to "paste" the instructions.<br>
>><br>
>> Much cleaner than dealing with strings, IMHO.<br>
>><br>
>> ~ Johannes<br>
>><br>
>><br>
>> On 6/1/21 12:16 PM, Przemyslaw Ossowski via llvm-dev wrote:<br>
>>> Hello,<br>
>>><br>
>>><br>
>>><br>
>>> I would like to add a pass which modifies IR by insertion set of IR<br>
>>> instructions somewhere in the middle of the basicblock,<br>
>>><br>
>>> like example below:<br>
>>><br>
>>><br>
>>><br>
>>>     %address = call i32* @llvm.target_intrinsic.getaddress()<br>
>>><br>
>>>     %value = load i32, i32* %address<br>
>>><br>
>>>     %addvalue = add nsw i32 %value, 10<br>
>>><br>
>>>     store i32 %addvalue, i32* %address<br>
>>><br>
>>><br>
>>><br>
>>> Is there any function available which would allow for parsing the string<br>
>>> (containing set of instructions) and generating instructions<br>
>> automatically<br>
>>> instead of manually calling functions creating instructions from<br>
>> IRBuilder?<br>
>>> ...at least for simple set of basic instructions<br>
>>><br>
>>><br>
>>> Regards,<br>
>>><br>
>>> Przemek<br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> LLVM Developers mailing list<br>
>>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
>>> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div>

</blockquote></div>