From 667d4b8de6dea70195ff12ef39a4deebffa2f5c7 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/IndMemRemoval.cpp | 4 ++-- lib/Transforms/Utils/InlineCost.cpp | 9 +++------ lib/Transforms/Utils/LowerInvoke.cpp | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'lib/Transforms') diff --git a/lib/Transforms/IPO/IndMemRemoval.cpp b/lib/Transforms/IPO/IndMemRemoval.cpp index 6b1f969..b55dea2 100644 --- a/lib/Transforms/IPO/IndMemRemoval.cpp +++ b/lib/Transforms/IPO/IndMemRemoval.cpp @@ -53,7 +53,7 @@ bool IndMemRemPass::runOnModule(Module &M) { if (Function* F = M.getFunction("free")) { if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) { Function* FN = Function::Create(F->getFunctionType(), - GlobalValue::LinkOnceLinkage, + GlobalValue::LinkOnceAnyLinkage, "free_llvm_bounce", &M); BasicBlock* bb = BasicBlock::Create("entry",FN); Instruction* R = ReturnInst::Create(bb); @@ -67,7 +67,7 @@ bool IndMemRemPass::runOnModule(Module &M) { if (Function* F = M.getFunction("malloc")) { if (F->isDeclaration() && F->arg_size() == 1 && !F->use_empty()) { Function* FN = Function::Create(F->getFunctionType(), - GlobalValue::LinkOnceLinkage, + GlobalValue::LinkOnceAnyLinkage, "malloc_llvm_bounce", &M); FN->setDoesNotAlias(0); BasicBlock* bb = BasicBlock::Create("entry",FN); diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp index b9f13d9..209ba92 100644 --- a/lib/Transforms/Utils/InlineCost.cpp +++ b/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/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp index 20cff90..b0364ec 100644 --- a/lib/Transforms/Utils/LowerInvoke.cpp +++ b/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.1