- Function *F = CGN ? CGN->getFunction() : 0;
-
- // If the only remaining use of the function is a dead constant
- // pointer ref, remove it.
- if (F && F->hasOneUse())
- if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(F->use_back()))
- if (CPR->use_empty()) {
- CPR->destroyConstant();
- if (F->hasInternalLinkage()) {
- // There *MAY* be an edge from the external call node to this
- // function. If so, remove it.
- CallGraphNode *EN = CG.getExternalCallingNode();
- CallGraphNode::iterator I = std::find(EN->begin(), EN->end(), CGN);
- if (I != EN->end()) EN->removeCallEdgeTo(CGN);
- }
- }
+ if (Function *F = CGN ? CGN->getFunction() : 0) {
+ // If the only remaining users of the function are dead constants, remove
+ // them.
+ F->removeDeadConstantUsers();
+
+ if ((F->hasLinkOnceLinkage() || F->hasInternalLinkage()) &&
+ F->use_empty()) {
+
+ // Remove any call graph edges from the function to its callees.
+ while (!CGN->empty())
+ CGN->removeCallEdgeTo((CGN->end()-1)->second);