[LLVMdev] LLVM IR for inline functions

Robinson, Paul Paul_Robinson at playstation.sony.com
Sun Apr 19 08:05:02 PDT 2015


> C has weird inline semantics.
> 
> Try compiling the same thing as C++ & you might get something more
> reasonable?

Weird indeed. In C, an 'inline' function definition with external linkage
may be ignored (the compiler may choose to treat it as an external call).
Making func1() 'static inline' emits IR for func1() with the 'inlinehint'
attribute; the front-end does not inline it for you.  This is true for
either C or C++.
--paulr

> 
> On Sat, Apr 18, 2015 at 6:36 PM, Zhoulai <zell08v at gmail.com> wrote:
> > Hi,
> >
> > I have a naive question on how to generate LLVM IR for inline functions.
> I
> > have compiled this C code:
> >
> > inline void func1()
> > {
> > int x=3;
> > }
> > void func2()
> > {
> > func1();
> > int y = 4;
> >
> > }
> >
> > into LLVM IR, using
> >
> > clang -emit-llvm -S -c <filename>
> >
> > But the generated LLVM IR file does *not* have func1() expanded (see
> below
> > for the relevant parts).
> >
> > ; Function Attrs: nounwind uwtable
> > define void @func2() #0 {
> > entry:
> > %y = alloca i32, align 4
> > call void (...)* @func1()
> > store i32 4, i32* %y, align 4
> > ret void
> > }
> >
> > declare void @func1(...) #1
> >
> > Question: Do I need to pass some special command line options so to make
> > func1() expanded in the LLVM IR? Thanks.
> >
> > Zhoulai
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> >
> _______________________________________________
> 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