[llvm-commits] CVS: llvm/lib/Transforms/IPO/Inliner.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Apr 12 00:38:01 PDT 2004


Changes in directory llvm/lib/Transforms/IPO:

Inliner.cpp updated: 1.8 -> 1.9

---
Log message:

Actually update the call graph as the inliner changes it.  This allows us to 
execute other CallGraphSCCPasses after the inliner without crashing.


---
Diffs of the changes:  (+20 -1)

Index: llvm/lib/Transforms/IPO/Inliner.cpp
diff -u llvm/lib/Transforms/IPO/Inliner.cpp:1.8 llvm/lib/Transforms/IPO/Inliner.cpp:1.9
--- llvm/lib/Transforms/IPO/Inliner.cpp:1.8	Sun Apr 11 23:06:56 2004
+++ llvm/lib/Transforms/IPO/Inliner.cpp	Mon Apr 12 00:37:29 2004
@@ -93,7 +93,21 @@
         // Attempt to inline the function...
         if (InlineFunction(CS)) {
           ++NumInlined;
+
+          // Update the call graph by deleting the edge from Callee to Caller
+          CallGraphNode *CalleeNode = CG[Callee];
+          CallGraphNode *CallerNode = CG[Caller];
+          CallerNode->removeCallEdgeTo(CalleeNode);
+
+          // Since we inlined all uninlinable call sites in the callee into the
+          // caller, add edges from the caller to all of the callees of the
+          // callee.
+          for (CallGraphNode::iterator I = CalleeNode->begin(),
+                 E = CalleeNode->end(); I != E; ++I)
+            CallerNode->addCalledFunction(*I);
   
+          // If the only remaining use of the function is a dead constant
+          // pointer ref, remove it.
           if (Callee->hasOneUse())
             if (ConstantPointerRef *CPR =
                 dyn_cast<ConstantPointerRef>(Callee->use_back()))
@@ -110,7 +124,12 @@
             if (I != SCCFunctions.end())    // Remove function from this SCC.
               SCCFunctions.erase(I);
 
-            Callee->getParent()->getFunctionList().erase(Callee);
+            // Remove any call graph edges from the callee to its callees.
+            while (CalleeNode->begin() != CalleeNode->end())
+              CalleeNode->removeCallEdgeTo(*(CalleeNode->end()-1));
+
+            // Removing the node for callee from the call graph and delete it.
+            delete CG.removeFunctionFromModule(CalleeNode);
             ++NumDeleted;
           }
           Changed = true;





More information about the llvm-commits mailing list