[llvm-commits] [llvm] r80540 - /llvm/trunk/lib/Transforms/IPO/Inliner.cpp

Chris Lattner sabre at nondot.org
Sun Aug 30 22:34:32 PDT 2009


Author: lattner
Date: Mon Aug 31 00:34:32 2009
New Revision: 80540

URL: http://llvm.org/viewvc/llvm-project?rev=80540&view=rev
Log:
comment and simplify some code.

Modified:
    llvm/trunk/lib/Transforms/IPO/Inliner.cpp

Modified: llvm/trunk/lib/Transforms/IPO/Inliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Inliner.cpp?rev=80540&r1=80539&r2=80540&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Inliner.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Inliner.cpp Mon Aug 31 00:34:32 2009
@@ -231,12 +231,18 @@
     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<DbgInfoIntrinsic>(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<IntrinsicInst>(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 @@
     // 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 @@
       // 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.





More information about the llvm-commits mailing list