[LLVMdev] Inlining

Nick Lewycky nicholas at mxc.ca
Fri Jan 8 21:17:58 PST 2010


Dustin Laurence wrote:
> On 01/08/2010 02:10 PM, John McCall wrote:
>
>   
>> 'llc' is an IR-to-assembly compiler;  at -O3 it does some pretty neat
>> machine-code and object-file optimizations, but it does not apply
>> high-level optimizations like CSE or inlining.  'opt' is the tool
>> which does IR-to-IR optimization.
>>     
>
> A vital clue, but I'm still not getting it:
>
> ---
> gemini:~/Projects/Nil/nil(0)$ make testInline.optdis.ll
> llvm-as testInline.ll
> opt -always-inline testInline.bc -o testInline.optbc
> llvm-dis -f testInline.optbc -o testInline.optdis.ll
> rm testInline.bc testInline.optbc
> gemini:~/Projects/Nil/nil(0)$ cat testInline.optdis.ll
> ; ModuleID = 'testInline.optbc'
>
> define linkonce fastcc i32 @foo(i32 %arg) alwaysinline {
>   
Try using 'internal' linkage instead of 'linkonce'. If you're sure you 
really want linkonce then you'd need to use linkonce_odr to get inlining 
here.

Also, drop the alwaysinline attribute and '-always-inline' flag. The 
normal inliner (aka. "opt -inline" which is run as part of "opt -O3") 
should inline it.

Nick
>   %result = mul i32 %arg, 7                       ; <i32> [#uses=1]
>   ret i32 %result
> }
>
> define i32 @main(i32 %argc, i8** %argv) {
>   %retVal = call fastcc i32 @foo(i32 6) alwaysinline ; <i32> [#uses=1]
>   ret i32 %retVal
> }
> gemini:~/Projects/Nil/nil(0)$
> ---
>
> Perhaps the -always-inline pass has a prerequisite pass?  I also tried
> it with "-O3 -always-inline", which got halfway there:
>
> ---
> ; ModuleID = 'testInline.optbc'
>
> define linkonce fastcc i32 @foo(i32 %arg) alwaysinline {
>   %result = mul i32 %arg, 7                       ; <i32> [#uses=1]
>   ret i32 %result
> }
>
> define i32 @main(i32 %argc, i8** nocapture %argv) {
>   %retVal = tail call fastcc i32 @foo(i32 6) alwaysinline ; <i32> [#uses=1]
>   ret i32 %retVal
> }
> ---
>
> I'm pleased to get the tailcall optimization, but in this case was
> looking for the 'no call at all' optimization. :-)
>
> Dustin
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>   




More information about the llvm-dev mailing list