<div dir="auto">Hi all,<div dir="auto"><br></div><div dir="auto">I solved it. I just added the keyword "__attribute__((always_inline))" before the function signature foo. I didn't add any extern inline or static inline or inline keyword. LLVM marks this function as an alwaysinline function. So when I add that synthetically with my transform pass the function is called from bar. However, the function foo is inlined when it is turned into machine code ultimately. That's what I wanted. Thanks for all your help.<br><br><div data-smartmail="gmail_signature" dir="auto">Regards,<br>Soham Sinha<br>CS PhD Student<br>Boston University</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 17, 2018, 12:47 AM Nema, Ashutosh <<a href="mailto:Ashutosh.Nema@amd.com">Ashutosh.Nema@amd.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_-6350598039151582633WordSection1">
<p class="MsoNormal">Hi Soham,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">“extern inline” keyword will help in this case, with this keyword compiler is forced to keeps the definition of the function and make it available for the external usage.<u></u><u></u></p>
<p class="MsoNormal">Also it retains the “inlinehint” attribute on the function, with that lto inliner may make it inline.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Best,<u></u><u></u></p>
<p class="MsoNormal">Ashutosh<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="margin-left:.5in"><b>From:</b> llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>Mehdi AMINI via llvm-dev<br>
<b>Sent:</b> Thursday, May 17, 2018 9:42 AM<br>
<b>To:</b> <a href="mailto:soham1@bu.edu" target="_blank" rel="noreferrer">soham1@bu.edu</a><br>
<b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [llvm-dev] How to inline function from other file in IR<u></u><u></u></p>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">Hi Soham,<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Are you intending to use the inline keyword in order to control the inlining optimization?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">The inline keyword is not doing this, it is changing the linkage type of the symbol and instruct the compiler to discard it if there is no call left, and also will instruct the linker to deduplicate. For instance
 if multiple file include a header that defines an inline function, this function could end up in multiple objects. Without the inline keyword you would get linker errors for duplicate symbols.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">So, the question become: why do you want foo to be inline in bar? If it is for performance then you don't need the keyword and you should rely on the optimizer to "do the right thing": running `opt -O2` on the resulting
 .ll file you get after llvm-link and after running your pass that adds the call should be enough.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Best,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">-- <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Mehdi<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0in;margin-bottom:12.0pt;margin-left:.5in">
<u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Le mar. 15 mai 2018 à 16:34, Soham Sinha via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a>> a écrit :<u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal" style="margin-left:.5in">Hello,<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">How can I inline a function mentioned in other file?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">I have an inline function <i>foo</i> in C source file (a.c) which is not referenced in this file. I compile this file to a.ll (I notice that the compiled a.ll doesn't have
<i>foo</i>'s definition, probably because it was inlined but not called anywhere)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">I have another C source file b.c with function
<i>bar</i>; I compile this to b.ll<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">I link these two files with llvm-link<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">I have written a pass which inserts
<i>foo </i>function calls to the bar function at some points. I want foo function calls to be
<i>inlined</i>. However, I get  compilation error because <i>foo </i>is not found (a.ll doesn't have foo)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">If I remove the inline attribute of foo in a.c, I get the correctly compilation, with calls to foo inserted in bar from b.c<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">How do I achieve this kind of inline-ing?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><br clear="all">
<u></u><u></u></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Regards,<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">Soham Sinha<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">PhD Student, Department of Computer Science<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Boston University<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="margin-left:.5in">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" rel="noreferrer">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div>
</div>

</blockquote></div>