From b7c6bf1e073088635951435acedff793add1cefd Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Wed, 5 Nov 2008 01:39:16 +0000 Subject: [PATCH] Do now allow InlineAlways pass to remove dead functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58744 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Transforms/IPO/InlinerPass.h | 4 ++++ lib/Transforms/IPO/InlineAlways.cpp | 3 +++ lib/Transforms/IPO/Inliner.cpp | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/include/llvm/Transforms/IPO/InlinerPass.h b/include/llvm/Transforms/IPO/InlinerPass.h index 082dd82a67e..7c3632fdce1 100644 --- a/include/llvm/Transforms/IPO/InlinerPass.h +++ b/include/llvm/Transforms/IPO/InlinerPass.h @@ -61,6 +61,10 @@ struct Inliner : public CallGraphSCCPass { /// virtual float getInlineFudgeFactor(CallSite CS) = 0; + /// removeDeadFunctions - Remove dead functions that are not included in + /// DNR (Do Not Remove) list. + bool removeDeadFunctions(CallGraph &CG, + SmallPtrSet *DNR = NULL); private: // InlineThreshold - Cache the value here for easy access. unsigned InlineThreshold; diff --git a/lib/Transforms/IPO/InlineAlways.cpp b/lib/Transforms/IPO/InlineAlways.cpp index d809b5aed17..9031432162e 100644 --- a/lib/Transforms/IPO/InlineAlways.cpp +++ b/lib/Transforms/IPO/InlineAlways.cpp @@ -45,6 +45,9 @@ namespace { float getInlineFudgeFactor(CallSite CS) { return CA.getInlineFudgeFactor(CS); } + virtual bool doFinalization(CallGraph &CG) { + return removeDeadFunctions(CG, &NeverInline); + } virtual bool doInitialization(CallGraph &CG); }; } diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index 2321047a375..418b2b70cb6 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -204,6 +204,13 @@ bool Inliner::runOnSCC(const std::vector &SCC) { // doFinalization - Remove now-dead linkonce functions at the end of // processing to avoid breaking the SCC traversal. bool Inliner::doFinalization(CallGraph &CG) { + return removeDeadFunctions(CG); +} + + /// removeDeadFunctions - Remove dead functions that are not included in + /// DNR (Do Not Remove) list. +bool Inliner::removeDeadFunctions(CallGraph &CG, + SmallPtrSet *DNR) { std::set FunctionsToRemove; // Scan for all of the functions, looking for ones that should now be removed @@ -215,6 +222,9 @@ bool Inliner::doFinalization(CallGraph &CG) { // them. F->removeDeadConstantUsers(); + if (DNR && DNR->count(F)) + continue; + if ((F->hasLinkOnceLinkage() || F->hasInternalLinkage()) && F->use_empty()) { -- 2.34.1