Skip to content

Commit f33d66f

Browse files
committed
Merging from mainline.
llvm-svn: 31611
1 parent bad3d39 commit f33d66f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

llvm/lib/Transforms/IPO/Inliner.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,13 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
112112
// Calls to external functions are never inlinable.
113113
if (Callee->isExternal() ||
114114
CallSites[CSi].getInstruction()->getParent()->getParent() ==Callee){
115-
std::swap(CallSites[CSi], CallSites.back());
116-
CallSites.pop_back();
115+
if (SCC.size() == 1) {
116+
std::swap(CallSites[CSi], CallSites.back());
117+
CallSites.pop_back();
118+
} else {
119+
// Keep the 'in SCC / not in SCC' boundary correct.
120+
CallSites.erase(CallSites.begin()+CSi);
121+
}
117122
--CSi;
118123
continue;
119124
}
@@ -131,9 +136,16 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
131136

132137
// Attempt to inline the function...
133138
if (InlineCallIfPossible(CS, CG, SCCFunctions)) {
134-
// Remove this call site from the list.
135-
std::swap(CallSites[CSi], CallSites.back());
136-
CallSites.pop_back();
139+
// Remove this call site from the list. If possible, use
140+
// swap/pop_back for efficiency, but do not use it if doing so would
141+
// move a call site to a function in this SCC before the
142+
// 'FirstCallInSCC' barrier.
143+
if (SCC.size() == 1) {
144+
std::swap(CallSites[CSi], CallSites.back());
145+
CallSites.pop_back();
146+
} else {
147+
CallSites.erase(CallSites.begin()+CSi);
148+
}
137149
--CSi;
138150

139151
++NumInlined;

0 commit comments

Comments
 (0)