From d43d5e832f756c9d2c0c8ff4d2f51807a27cab8d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 31 Aug 2009 05:34:32 +0000 Subject: [PATCH] comment and simplify some code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80540 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/Inliner.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index 9b8e0a1fc4d..61772651583 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -231,12 +231,18 @@ bool Inliner::runOnSCC(std::vector &SCC) { for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { CallSite CS = CallSite::get(I); - if (CS.getInstruction() == 0 || isa(I)) + // If this this isn't a call, or it is a call to an intrinsic, it can + // never be inlined. + if (CS.getInstruction() == 0 || isa(I)) continue; - if (CS.getCalledFunction() == 0 || - !CS.getCalledFunction()->isDeclaration()) - CallSites.push_back(CS); + // If this is a direct call to an external function, we can never inline + // it. If it is an indirect call, inlining may resolve it to be a + // direct call, so we keep it. + if (CS.getCalledFunction() && CS.getCalledFunction()->isDeclaration()) + continue; + + CallSites.push_back(CS); } } @@ -262,25 +268,12 @@ bool Inliner::runOnSCC(std::vector &SCC) { // Iterate over the outer loop because inlining functions can cause indirect // calls to become direct calls. for (unsigned CSi = 0; CSi != CallSites.size(); ++CSi) { - // We can only inline direct calls. CallSite CS = CallSites[CSi]; Function *Callee = CS.getCalledFunction(); - if (!Callee) continue; + // We can only inline direct calls to non-declarations. + if (Callee == 0 || Callee->isDeclaration()) continue; - // Calls to external functions are never inlinable. - if (Callee->isDeclaration()) { - if (SCC.size() == 1) { - std::swap(CallSites[CSi], CallSites.back()); - CallSites.pop_back(); - } else { - // Keep the 'in SCC / not in SCC' boundary correct. - CallSites.erase(CallSites.begin()+CSi); - } - --CSi; - continue; - } - // If the policy determines that we should inline this function, // try to do so. if (!shouldInline(CS)) @@ -294,7 +287,9 @@ bool Inliner::runOnSCC(std::vector &SCC) { // If we inlined the last possible call site to the function, delete the // function body now. if (Callee->use_empty() && Callee->hasLocalLinkage() && + // TODO: Can remove if in SCC now. !SCCFunctions.count(Callee) && + // The function may be apparently dead, but if there are indirect // callgraph references to the node, we cannot delete it yet, this // could invalidate the CGSCC iterator. -- 2.34.1