Hi Duncan- Forgive my confusion, but I can't help notice that LangRef states: 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. Why would linkonce be used to implement inline functions if it's not safe to inline linkonce functions? Alastair On 9 Jan 2010, at 08:15, Duncan Sands wrote:> Hi Dustin, > >> define linkonce fastcc i32 @foo(i32 %arg) alwaysinline > > linkonce implies that the function body may change at link time. Thus it would > be wrong to inline it, since the code being inlined would not be the final code. > Use linkonce_odr to tell the compiler that the function body can be replaced > only by an equivalent function body. > > Ciao, > > Duncan. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Hi Alastair,> Forgive my confusion, but I can't help notice that LangRef states: > > 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. > > Why would linkonce be used to implement inline functions if it's not safe to inline linkonce functions?I was wrong - linkonce is an exception to the general rule that a "weak" linkage type prevents inlining unless of the "_odr" form. Ciao, Duncan.
On 01/09/2010 08:41 AM, Duncan Sands wrote:> I was wrong - linkonce is an exception to the general rule that a "weak" linkage > type prevents inlining unless of the "_odr" form.Except it really did prevent inlining in my test. If I follow, and I probably don't, what you said matched the behavior of LLVM and the docs didn't. Dustin
On Jan 9, 2010, at 8:41 AM, Duncan Sands wrote:> Hi Alastair, > >> Forgive my confusion, but I can't help notice that LangRef states: >> >> 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. >> >> Why would linkonce be used to implement inline functions if it's not safe to inline linkonce functions? > > I was wrong - linkonce is an exception to the general rule that a "weak" linkage > type prevents inlining unless of the "_odr" form.Actually, the inliner doesn't inline linkonce either, because we have: InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, SmallPtrSet<const Function *, 16> &NeverInline) { ... // Don't inline functions which can be redefined at link-time to mean // something else. Don't inline functions marked noinline. if (Callee->mayBeOverridden() || Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee)) return llvm::InlineCost::getNever(); I improved the langref description of linkonce in r93066. -Chris