On 01/08/2010 09:17 PM, Nick Lewycky wrote:> Try using 'internal' linkage instead of 'linkonce'.That did it, thanks. --- gemini:~/Projects/LLVM/Tests/Inline(0)$ cat testInline.optdis.ll ; ModuleID = 'testInline.optbc' define i32 @main(i32 %argc, i8** nocapture %argv) nounwind readnone { ret i32 42 } gemini:~/Projects/LLVM/Tests/Inline(0)$ ---> If you're sure you > really want linkonce then you'd need to use linkonce_odr to get inlining > here.I'm sure of nothing. I only used it because the IR Reference says linkonce: Globals with "linkonce" linkage are merged with other globals of the same name when linkage occurs. This is typically used to implement inline functions, templates, or other code which must be generated in each translation unit that uses it. Unreferenced linkonce globals are allowed to be discarded. So I thought it was telling me to use linkonce for inline functions.+ A bit more experimentation shows that it still inlines with the default linkage, the only difference being it retains a non-inlined version as well. With 'internal' it omits the non-inlined version. I think I see why that's true.> 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.Yes, it still did after I removed them. Since I'm clearly not guessing well here, when would one want to use "alwaysinline"? Dustin
Hello Dustin, Always inline is the closest to a preprocessor macro you can get in LLVM Assembly since it doesn't have a preprocessor at all. LLVM does aggressive inlining for functions used only once so those instances don't require specification as alwaysinline. --Sam ----- Original Message ----> From: Dustin Laurence <dllaurence at dslextreme.com> > Cc: llvmdev at cs.uiuc.edu > Sent: Sat, January 9, 2010 3:46:29 AM > Subject: Re: [LLVMdev] Inlining > > > 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. > > Yes, it still did after I removed them. Since I'm clearly not guessing > well here, when would one want to use "alwaysinline"? > > Dustin
On 01/09/2010 10:00 AM, Samuel Crow wrote:> > Always inline is the closest to a preprocessor macro you can get in > LLVM Assembly since it doesn't have a preprocessor at all.Mine does. :-)> ...LLVM does > aggressive inlining for functions used only once so those instances > don't require specification as alwaysinline.What I'm trying to do is understand the practical use cases. Concrete example: I have some little type accessor and conversion functions that are typically two or three instructions long because all they really do is manipulate tag data in the low-order bits of pointers. (I'm not exactly innovative, am I?) While small, they are called all over the place for boxing and unboxing language-level objects. In C they would be explicitly inline. What is the LLVM equivalent? My guess is the optimizer will always inline such tiny functions no matter what as it's probably both a space and a time win, so maybe I need a different example. Suppose they were typically five, or ten, or twenty, or forty instructions long? Who is responsible for deciding on the advisability of inlining? The front-end (which in this case is actually me?)? That would be the equivalent of the C99/C++ 'inline' compiler hint. Or in LLVM is it better not to give manual compiler hints about inlining in most cases and let the optimizers decide? I suppose it's a fuzzy question because I'm fishing for intended usage, not just semantics. Dustin