diff options
| author | Mehdi Amini <mehdi.amini@apple.com> | 2016-05-02 22:11:27 +0000 |
|---|---|---|
| committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-05-02 22:11:27 +0000 |
| commit | bda9b2ae9e69e5de7ce76e70c9cd6519d90a0226 (patch) | |
| tree | d70fbc04e3bbafde54b3b958c73fc59dd3a2842c | |
| parent | 3ba6535096a4a1abd57f7813183ac8fa0bccfc39 (diff) | |
| download | bcm5719-llvm-bda9b2ae9e69e5de7ce76e70c9cd6519d90a0226.tar.gz bcm5719-llvm-bda9b2ae9e69e5de7ce76e70c9cd6519d90a0226.zip | |
ThinLTO: do not import function whose linkage prevents inlining.
There is not point in importing a "weak" or a "linkonce" function
since we won't be able to inline it anyway.
We already had a targeted check for WeakAny, this is using the
same check on GlobalValue as the inline, i.e.
isMayBeOverriddenLinkage()
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 268315
| -rw-r--r-- | llvm/include/llvm/IR/GlobalValue.h | 46 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/FunctionImport.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/Transforms/FunctionImport/Inputs/funcimport.ll | 5 | ||||
| -rw-r--r-- | llvm/test/Transforms/FunctionImport/funcimport.ll | 5 |
4 files changed, 38 insertions, 22 deletions
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h index 0d12fe86819..503023809e3 100644 --- a/llvm/include/llvm/IR/GlobalValue.h +++ b/llvm/include/llvm/IR/GlobalValue.h @@ -124,26 +124,7 @@ private: /// non-equivalent at link time. For example, if a function has weak linkage /// then the code defining it may be replaced by different code. bool mayBeOverridden() const { - switch (getLinkage()) { - case WeakAnyLinkage: - case LinkOnceAnyLinkage: - case CommonLinkage: - case ExternalWeakLinkage: - return true; - - case AvailableExternallyLinkage: - case LinkOnceODRLinkage: - case WeakODRLinkage: - // The above three cannot be overridden but can be de-refined. - - case ExternalLinkage: - case AppendingLinkage: - case InternalLinkage: - case PrivateLinkage: - return false; - } - - llvm_unreachable("Fully covered switch above!"); + return isMayBeOverriddenLinkage(getLinkage()); } protected: @@ -285,6 +266,31 @@ public: return Linkage == CommonLinkage; } + /// Whether the definition of this global may be replaced by something + /// non-equivalent at link time. For example, if a function has weak linkage + /// then the code defining it may be replaced by different code. + static bool isMayBeOverriddenLinkage(LinkageTypes Linkage) { + switch (Linkage) { + case WeakAnyLinkage: + case LinkOnceAnyLinkage: + case CommonLinkage: + case ExternalWeakLinkage: + return true; + + case AvailableExternallyLinkage: + case LinkOnceODRLinkage: + case WeakODRLinkage: + // The above three cannot be overridden but can be de-refined. + + case ExternalLinkage: + case AppendingLinkage: + case InternalLinkage: + case PrivateLinkage: + return false; + } + llvm_unreachable("Fully covered switch above!"); + } + /// Whether the definition of this global may be discarded if it is not used /// in its compilation unit. static bool isDiscardableIfUnused(LinkageTypes Linkage) { diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index ec82248d78b..d9860a908d0 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -156,8 +156,8 @@ selectCallee(const ModuleSummaryIndex &Index, CalleeSummaryList, [&](const std::unique_ptr<GlobalValueSummary> &SummaryPtr) { auto *GVSummary = SummaryPtr.get(); - if (GlobalValue::isWeakAnyLinkage(GVSummary->linkage())) - // There is no point in importing weak symbols, we can't inline them + if (GlobalValue::isMayBeOverriddenLinkage(GVSummary->linkage())) + // There is no point in importing these, we can't inline them return false; if (auto *AS = dyn_cast<AliasSummary>(GVSummary)) { GVSummary = &AS->getAliasee(); diff --git a/llvm/test/Transforms/FunctionImport/Inputs/funcimport.ll b/llvm/test/Transforms/FunctionImport/Inputs/funcimport.ll index 03ea3647fd7..fa96b8ea266 100644 --- a/llvm/test/Transforms/FunctionImport/Inputs/funcimport.ll +++ b/llvm/test/Transforms/FunctionImport/Inputs/funcimport.ll @@ -75,6 +75,11 @@ entry: ret void } +define linkonce void @linkoncefunc2() #0 { +entry: + ret void +} + define internal i32 @staticfunc() #0 { entry: ret i32 1 diff --git a/llvm/test/Transforms/FunctionImport/funcimport.ll b/llvm/test/Transforms/FunctionImport/funcimport.ll index f0df3200555..478613a2475 100644 --- a/llvm/test/Transforms/FunctionImport/funcimport.ll +++ b/llvm/test/Transforms/FunctionImport/funcimport.ll @@ -28,6 +28,7 @@ entry: call void (...) @setfuncptr() call void (...) @callfuncptr() call void (...) @weakfunc() + call void (...) @linkoncefunc2() call void (...) @referencelargelinkonce() ret i32 0 } @@ -94,6 +95,10 @@ declare void @referencelargelinkonce(...) ; CHECK-DAG: declare void @weakfunc(...) declare void @weakfunc(...) #1 +; Won't import linkonce func +; CHECK-DAG: declare void @linkoncefunc2(...) +declare void @linkoncefunc2(...) #1 + ; INSTLIMDEF-DAG: Import funcwithpersonality ; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { ; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}() |

