[LLVMdev] Forcing function inline not working

Dale Johannesen dalej at apple.com
Wed Sep 16 20:17:49 PDT 2009


On Sep 16, 2009, at 6:55 PM, madiyaan wrote:

>
> I have the following code:
>
> static inline void foo() __attribute((always_inline));
>
> int a;
> static inline void foo()
> {
>  a++;
> }
>
> int main(int argc, char *argv[])
> {
>  foo();
>  return 0;
> }

This works fine in current sources.  You should upgrade; 2.5 has been  
out for a while and 2.6 will be soon.

> However, the code generated by llvm 2.4 toolchain does not inline this
> function. opt retains the function call. Here is the output when I  
> try to
> compile with -debug-only=inline:
>
> ..\..\..\win32\bin\win32\debug\opt.exe -O3 -debug-only=inline - 
> mem2reg -f -o
> test_opt.bc test.bc
> Inliner visiting SCC: foo: 0 call sites.
> Inliner visiting SCC: main: 1 call sites.
>    Inlining: cost=always, Call:        call void (...)* @foo()
> Inliner visiting SCC: INDIRECTNODE: 0 call sites.
>
> Here is the .ll file:
>
> ; ModuleID = 'test_opt.bc'
> target datalayout =
> "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32- 
> f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
> target triple = "i386-pc-win32"
> @a = common global i32 0, align 4		; <i32*> [#uses=2]
>
> define i32 @main(i32 %argc, i8** %argv) nounwind {
> entry:
> 	tail call void (...)* @foo()
> 	ret i32 0
> }
>
> define internal void @foo(...) nounwind alwaysinline {
> entry:
> 	%tmp = load i32* @a		; <i32> [#uses=1]
> 	%inc = add i32 %tmp, 1		; <i32> [#uses=1]
> 	store i32 %inc, i32* @a
> 	ret void
> }
>
>
> What am I doing wrong here? Is there a way to force a function to be  
> inlined
> by opt?
>
> Best Regards,
> -- 
> View this message in context: http://www.nabble.com/Forcing-function-inline-not-working-tp25483934p25483934.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
>
> _______________________________________________
> 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