[LLVMdev] Inlining

Chris Lattner clattner at apple.com
Sat Jan 9 11:15:51 PST 2010


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



More information about the llvm-dev mailing list