From 2c719cc11781bba190687b3a68fea88d88e2fef8 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 20 Apr 2016 04:17:36 +0000 Subject: FunctionImport: make sure we always select the right callee in presence of alias From: Mehdi Amini llvm-svn: 266854 --- llvm/lib/Transforms/IPO/FunctionImport.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index eef7385dd08..9d7d78a30a1 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -86,12 +86,21 @@ selectCallee(const GlobalValueInfoList &CalleeInfoList, unsigned Threshold) { assert(GlobInfo->summary() && "We should not have a Global Info without summary"); auto *GVSummary = GlobInfo->summary(); - if (auto *AS = dyn_cast(GVSummary)) + if (GlobalValue::isWeakAnyLinkage(GVSummary->linkage())) + // There is no point in importing weak symbols, we can't inline them + return false; + if (auto *AS = dyn_cast(GVSummary)) { GVSummary = &AS->getAliasee(); - auto *Summary = cast(GVSummary); + // Alias can't point to "available_externally". However when we import + // linkOnceODR the linkage does not change. So we import the alias + // and aliasee only in this case. + // FIXME: we should import alias as available_externally *function*, + // the destination module does need to know it is an alias. + if (!GlobalValue::isLinkOnceODRLinkage(GVSummary->linkage())) + return false; + } - if (GlobalValue::isWeakAnyLinkage(Summary->linkage())) - return false; + auto *Summary = cast(GVSummary); if (Summary->instCount() > Threshold) return false; @@ -166,16 +175,9 @@ static void computeImportForFunction( if (isa(CalleeSummary)) { ResolvedCalleeSummary = cast( &cast(CalleeSummary)->getAliasee()); - if (!GlobalValue::isLinkOnceODRLinkage( - ResolvedCalleeSummary->linkage())) { - // Alias can't point to "available_externally". However when we import - // linkOnceODR the linkage does not change. So we import the alias - // and aliasee only in this case. - // FIXME: we should import alias as available_externally *function*, the - // destination module does need to know it is an alias. - DEBUG(dbgs() << "ignored! Aliasee is not linkonce_odr.\n"); - continue; - } + assert( + GlobalValue::isLinkOnceODRLinkage(ResolvedCalleeSummary->linkage()) && + "Unexpected alias to a non-linkonceODR in import list"); } else ResolvedCalleeSummary = cast(CalleeSummary); -- cgit v1.2.3