@@ -54,8 +54,8 @@ static bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
54
54
E = CalleeNode->end (); I != E; ++I)
55
55
CallerNode->addCalledFunction (*I);
56
56
57
- // If we inlined the last possible call site to the function,
58
- // delete the function body now.
57
+ // If we inlined the last possible call site to the function, delete the
58
+ // function body now.
59
59
if (Callee->use_empty () && Callee->hasInternalLinkage () &&
60
60
!SCCFunctions.count (Callee)) {
61
61
DEBUG (std::cerr << " -> Deleting dead function: "
@@ -64,7 +64,7 @@ static bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
64
64
// Remove any call graph edges from the callee to its callees.
65
65
while (CalleeNode->begin () != CalleeNode->end ())
66
66
CalleeNode->removeCallEdgeTo (*(CalleeNode->end ()-1 ));
67
-
67
+
68
68
// Removing the node for callee from the call graph and delete it.
69
69
delete CG.removeFunctionFromModule (CalleeNode);
70
70
++NumDeleted;
@@ -167,27 +167,27 @@ bool Inliner::doFinalization(CallGraph &CG) {
167
167
// from the program. Insert the dead ones in the FunctionsToRemove set.
168
168
for (CallGraph::iterator I = CG.begin (), E = CG.end (); I != E; ++I) {
169
169
CallGraphNode *CGN = I->second ;
170
- Function *F = CGN ? CGN->getFunction () : 0 ;
171
-
172
- // If the only remaining users of the function are dead constants,
173
- // remove them.
174
- if (F) F->removeDeadConstantUsers ();
175
-
176
- if (F && (F->hasLinkOnceLinkage () || F->hasInternalLinkage ()) &&
177
- F->use_empty ()) {
178
-
179
- // Remove any call graph edges from the function to its callees.
180
- while ( CGN->begin () != CGN->end ())
181
- CGN-> removeCallEdgeTo (*(CGN-> end ()- 1 ));
182
-
183
- // If the function has external linkage (basically if it's a linkonce
184
- // function) remove the edge from the external node to the callee
185
- // node.
186
- if (!F-> hasInternalLinkage ())
187
- CG. getExternalCallingNode ()-> removeCallEdgeTo (CGN);
188
-
189
- // Removing the node for callee from the call graph and delete it.
190
- FunctionsToRemove. insert (CGN);
170
+ if ( Function *F = CGN ? CGN->getFunction () : 0 ) {
171
+ // If the only remaining users of the function are dead constants,
172
+ // remove them.
173
+ bool HadDeadConstantUsers = !F-> use_empty ();
174
+ F->removeDeadConstantUsers ();
175
+
176
+ if ( (F->hasLinkOnceLinkage () || F->hasInternalLinkage ()) &&
177
+ F->use_empty ()) {
178
+ // Remove any call graph edges from the function to its callees.
179
+ while (CGN-> begin () != CGN-> end ())
180
+ CGN->removeCallEdgeTo (*( CGN->end ()- 1 ));
181
+
182
+ // If the function has external linkage (basically if it's a linkonce
183
+ // function) remove the edge from the external node to the callee
184
+ // node.
185
+ if (!F-> hasInternalLinkage () || HadDeadConstantUsers)
186
+ CG. getExternalCallingNode ()-> removeCallEdgeTo (CGN);
187
+
188
+ // Removing the node for callee from the call graph and delete it.
189
+ FunctionsToRemove. insert (CGN);
190
+ }
191
191
}
192
192
}
193
193
0 commit comments