Skip to content

Commit f65cd04

Browse files
[ModuleInliner] Remove an extraneous pair of std::push_heap and std::pop_heap (NFC) (llvm#69672)
Immediately after the "while" loop in adjust, Heap.back() is guaranteed to be the highest priority item for the current values of Priorities. std::push_back() at the end of adjust moves the highest priority item to Heap.front(), but std::pop_heap() in pop moves it right back to Heap.back(). This roundtrip is wasteful. This patch removes the extraneous pair of std::push_heap and std::pop_heap. This patch cuts down about 45% of calls to std::push_heap and std::pop_heap in InlineOrder.cpp while building clang with FDO+ThinLTO. Strictly speaking, removing the pair of calls may change the order in which call sites with identical priorities are removed from the priority queue, but we do not need to worry about that. Since the functionality of adjust becomes more like a smart version of pop_heap, this patch renames adjust to pop_heap_adjust.
1 parent d79051f commit f65cd04

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

llvm/lib/Analysis/InlineOrder.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,12 @@ class PriorityInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
222222
// desirability of the front call site decreases, an updated one would be
223223
// pushed right back into the heap. For simplicity, those cases where the
224224
// desirability of a call site increases are ignored here.
225-
void adjust() {
225+
void pop_heap_adjust() {
226226
std::pop_heap(Heap.begin(), Heap.end(), isLess);
227227
while (updateAndCheckDecreased(Heap.back())) {
228228
std::push_heap(Heap.begin(), Heap.end(), isLess);
229229
std::pop_heap(Heap.begin(), Heap.end(), isLess);
230230
}
231-
std::push_heap(Heap.begin(), Heap.end(), isLess);
232231
}
233232

234233
public:
@@ -253,9 +252,8 @@ class PriorityInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
253252

254253
T pop() override {
255254
assert(size() > 0);
256-
adjust();
255+
pop_heap_adjust();
257256

258-
std::pop_heap(Heap.begin(), Heap.end(), isLess);
259257
CallBase *CB = Heap.pop_back_val();
260258
T Result = std::make_pair(CB, InlineHistoryMap[CB]);
261259
InlineHistoryMap.erase(CB);

0 commit comments

Comments
 (0)