Reapply 55859. This doesn't change anything as
authorDuncan Sands <baldrick@free.fr>
Mon, 8 Sep 2008 11:05:51 +0000 (11:05 +0000)
committerDuncan Sands <baldrick@free.fr>
Mon, 8 Sep 2008 11:05:51 +0000 (11:05 +0000)
long as the callgraph is correct.  It checks
for wrong callgraphs more strictly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55894 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 00c804c4caf8556ed623067cb233ca6d29e3869b..e63db750ea3f9d66d6e9833a3643ef630317d0b5 100644 (file)
@@ -214,17 +214,12 @@ public:
     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.
index c8f25b07b8dcbb7fd369c827a22bcb4e168eb872..99848c8326999c126164a1c05850d1f0cd54b176 100644 (file)
@@ -272,26 +272,20 @@ void CallGraphNode::print(std::ostream &OS) const {
   else
     OS << "Call graph node <<null function: 0x" << this << ">>:\n";
 
-  for (const_iterator I = begin(), E = end(); I != E; ++I)
+  for (const_iterator I = begin(), E = end(); I != E; ++I) {
     if (I->second->getFunction())
-      OS << "  Calls function '" << I->second->getFunction()->getName() <<"'\n";
-  else
-    OS << "  Calls external node\n";
+      OS << "  Calls function '" << I->second->getFunction()->getName() << "'";
+    else
+      OS << "  Calls external node";
+    if (I->first.getInstruction())
+      OS << " from '" << *I->first.getInstruction() << "'";
+    OS << "\n";
+  }
   OS << "\n";
 }
 
 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.
index 630768fbdcdf847e7b92d834a915ac74f342f9c0..297c6c15414e38f6a50e1c5ff3108173a448e65b 100644 (file)
@@ -228,13 +228,10 @@ void PruneEH::DeleteBasicBlock(BasicBlock *BB) {
   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()));
   }
index cb9c28dcabb5b29d23d146ee4cdb13d017b6989e..b0e70bb89ad360cafef8b04bd2868e151aefbdfd 100644 (file)
@@ -143,16 +143,18 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
 /// 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 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
 
     // 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