From 12da8ce3d2b9c365b2e204fcf2b4002177fc6b8b Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Sat, 7 Mar 2009 15:45:40 +0000 Subject: Introduce new linkage types linkonce_odr, weak_odr, common_odr and extern_weak_odr. These are the same as the non-odr versions, except that they indicate that the global will only be overridden by an *equivalent* global. In C, a function with weak linkage can be overridden by a function which behaves completely differently. This means that IP passes have to skip weak functions, since any deductions made from the function definition might be wrong, since the definition could be replaced by something completely different at link time. This is not allowed in C++, thanks to the ODR (One-Definition-Rule): if a function is replaced by another at link-time, then the new function must be the same as the original function. If a language knows that a function or other global can only be overridden by an equivalent global, it can give it the weak_odr linkage type, and the optimizers will understand that it is alright to make deductions based on the function body. The code generators on the other hand map weak and weak_odr linkage to the same thing. llvm-svn: 66339 --- llvm/lib/Transforms/Utils/InlineCost.cpp | 9 +++------ llvm/lib/Transforms/Utils/LowerInvoke.cpp | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Transforms/Utils') diff --git a/llvm/lib/Transforms/Utils/InlineCost.cpp b/llvm/lib/Transforms/Utils/InlineCost.cpp index b9f13d923b5..209ba927181 100644 --- a/llvm/lib/Transforms/Utils/InlineCost.cpp +++ b/llvm/lib/Transforms/Utils/InlineCost.cpp @@ -182,12 +182,9 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, // Don't inline functions which can be redefined at link-time to mean // something else. - // FIXME: We allow link-once linkage since in practice all versions of - // the function have the same body (C++ ODR) - but the LLVM definition - // of LinkOnceLinkage doesn't require this. - if ((Callee->mayBeOverridden() && !Callee->hasLinkOnceLinkage()) || - // Don't inline functions marked noinline. - Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee)) + if (Callee->mayBeOverridden() || + // Don't inline functions marked noinline. + Callee->hasFnAttr(Attribute::NoInline) || NeverInline.count(Callee)) return llvm::InlineCost::getNever(); // InlineCost - This value measures how good of an inline candidate this call diff --git a/llvm/lib/Transforms/Utils/LowerInvoke.cpp b/llvm/lib/Transforms/Utils/LowerInvoke.cpp index 20cff90643f..b0364ecd61c 100644 --- a/llvm/lib/Transforms/Utils/LowerInvoke.cpp +++ b/llvm/lib/Transforms/Utils/LowerInvoke.cpp @@ -139,7 +139,7 @@ bool LowerInvoke::doInitialization(Module &M) { // already exists. if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) { JBListHead = new GlobalVariable(PtrJBList, false, - GlobalValue::LinkOnceLinkage, + GlobalValue::LinkOnceAnyLinkage, Constant::getNullValue(PtrJBList), "llvm.sjljeh.jblist", &M); } -- cgit v1.2.3