[llvm-commits] [llvm] r55859 - in /llvm/trunk: include/llvm/Analysis/CallGraph.h lib/Analysis/IPA/CallGraph.cpp lib/Transforms/IPO/PruneEH.cpp lib/Transforms/Utils/InlineFunction.cpp

Duncan Sands baldrick at free.fr
Fri Sep 5 14:43:05 PDT 2008


Author: baldrick
Date: Fri Sep  5 16:43:04 2008
New Revision: 55859

URL: http://llvm.org/viewvc/llvm-project?rev=55859&view=rev
Log:
Delete the removeCallEdgeTo callgraph method,
because it does not maintain a correct list
of callsites.  I discovered (see following
commit) that the inliner will create a wrong
callgraph if it is fed a callgraph with
correct edges but incorrect callsites.  These
were created by Prune-EH, and while it wasn't
done via removeCallEdgeTo, it could have been
done via removeCallEdgeTo, which is an accident
waiting to happen.  Use removeCallEdgeFor
instead.

Modified:
    llvm/trunk/include/llvm/Analysis/CallGraph.h
    llvm/trunk/lib/Analysis/IPA/CallGraph.cpp
    llvm/trunk/lib/Transforms/IPO/PruneEH.cpp
    llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp

Modified: llvm/trunk/include/llvm/Analysis/CallGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/CallGraph.h?rev=55859&r1=55858&r2=55859&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/CallGraph.h (original)
+++ llvm/trunk/include/llvm/Analysis/CallGraph.h Fri Sep  5 16:43:04 2008
@@ -214,17 +214,12 @@
     CalledFunctions.clear();
   }
 
-  /// addCalledFunction add a function to the list of functions called by this
+  /// addCalledFunction - Add a function to the list of functions called by this
   /// one.
   void addCalledFunction(CallSite CS, CallGraphNode *M) {
     CalledFunctions.push_back(std::make_pair(CS, M));
   }
 
-  /// removeCallEdgeTo - This method removes a *single* edge to the specified
-  /// callee function.  Note that this method takes linear time, so it should be
-  /// used sparingly.
-  void removeCallEdgeTo(CallGraphNode *Callee);
-
   /// removeCallEdgeFor - This method removes the edge in the node for the
   /// specified call site.  Note that this method takes linear time, so it
   /// should be used sparingly.

Modified: llvm/trunk/lib/Analysis/IPA/CallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/CallGraph.cpp?rev=55859&r1=55858&r2=55859&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/IPA/CallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/CallGraph.cpp Fri Sep  5 16:43:04 2008
@@ -282,16 +282,6 @@
 
 void CallGraphNode::dump() const { print(cerr); }
 
-void CallGraphNode::removeCallEdgeTo(CallGraphNode *Callee) {
-  for (unsigned i = CalledFunctions.size(); ; --i) {
-    assert(i && "Cannot find callee to remove!");
-    if (CalledFunctions[i-1].second == Callee) {
-      CalledFunctions.erase(CalledFunctions.begin()+i-1);
-      return;
-    }
-  }
-}
-
 /// removeCallEdgeFor - This method removes the edge in the node for the
 /// specified call site.  Note that this method takes linear time, so it
 /// should be used sparingly.

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

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PruneEH.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PruneEH.cpp Fri Sep  5 16:43:04 2008
@@ -222,13 +222,10 @@
   CallGraphNode *CGN = CG[BB->getParent()];
   for (BasicBlock::iterator I = BB->end(), E = BB->begin(); I != E; ) {
     --I;
-    if (CallInst *CI = dyn_cast<CallInst>(I)) {
-      if (Function *Callee = CI->getCalledFunction())
-        CGN->removeCallEdgeTo(CG[Callee]);
-    } else if (InvokeInst *II = dyn_cast<InvokeInst>(I)) {
-      if (Function *Callee = II->getCalledFunction())
-        CGN->removeCallEdgeTo(CG[Callee]);
-    }
+    if (CallInst *CI = dyn_cast<CallInst>(I))
+      CGN->removeCallEdgeFor(CI);
+    else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
+      CGN->removeCallEdgeFor(II);
     if (!I->use_empty())
       I->replaceAllUsesWith(UndefValue::get(I->getType()));
   }

Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=55859&r1=55858&r2=55859&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Fri Sep  5 16:43:04 2008
@@ -143,16 +143,18 @@
 /// UpdateCallGraphAfterInlining - Once we have cloned code over from a callee
 /// into the caller, update the specified callgraph to reflect the changes we
 /// made.  Note that it's possible that not all code was copied over, so only
-/// some edges of the callgraph will be remain.
-static void UpdateCallGraphAfterInlining(const Function *Caller,
-                                         const Function *Callee,
+/// some edges of the callgraph may remain.
+static void UpdateCallGraphAfterInlining(CallSite CS,
                                          Function::iterator FirstNewBlock,
                                        DenseMap<const Value*, Value*> &ValueMap,
                                          CallGraph &CG) {
+  const Function *Caller = CS.getInstruction()->getParent()->getParent();
+  const Function *Callee = CS.getCalledFunction();
+
   // Update the call graph by deleting the edge from Callee to Caller
   CallGraphNode *CalleeNode = CG[Callee];
   CallGraphNode *CallerNode = CG[Caller];
-  CallerNode->removeCallEdgeTo(CalleeNode);
+  CallerNode->removeCallEdgeFor(CS);
 
   // Since we inlined some uninlined call sites in the callee into the caller,
   // add edges from the caller to all of the callees of the callee.
@@ -302,8 +304,7 @@
 
     // Update the callgraph if requested.
     if (CG)
-      UpdateCallGraphAfterInlining(Caller, CalledFunc, FirstNewBlock, ValueMap,
-                                   *CG);
+      UpdateCallGraphAfterInlining(CS, FirstNewBlock, ValueMap, *CG);
   }
 
   // If there are any alloca instructions in the block that used to be the entry





More information about the llvm-commits mailing list