diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp --- a/llvm/lib/Transforms/IPO/Inliner.cpp +++ b/llvm/lib/Transforms/IPO/Inliner.cpp @@ -736,6 +736,29 @@ return (int)Callee->getInstructionCount(); } + // A call site could become less desirable for inlining because of the size + // growth from prior inlining into the calee. This method is used to lazily + // update the desirability of a call site if it's decreasing. It is only + // called on pop() or front(), not every time the desirability changes. When + // the desirability of the front call site decreases, an updated one would be + // inserted right back into the queue. To keep simple, those cases where + // the desirability of a call site increases are ignored here. + void adjust() { + bool Changed = false; + do { + CallBase *CB = Heap.front().first; + const int PreviousGoodness = Heap.front().second; + const int CurrentGoodness = evaluate(CB); + Changed = PreviousGoodness < CurrentGoodness; + if (Changed) { + std::pop_heap(Heap.begin(), Heap.end(), cmp); + Heap.pop_back(); + Heap.push_back({CB, CurrentGoodness}); + std::push_heap(Heap.begin(), Heap.end(), cmp); + } + } while (Changed); + } + public: size_t size() override { return Heap.size(); } @@ -751,6 +774,8 @@ T pop() override { assert(size() > 0); + adjust(); + CallBase *CB = Heap.front().first; T Result = std::make_pair(CB, InlineHistoryMap[CB]); InlineHistoryMap.erase(CB); @@ -761,6 +786,8 @@ const_reference front() override { assert(size() > 0); + adjust(); + CallBase *CB = Heap.front().first; return *InlineHistoryMap.find(CB); } @@ -821,7 +848,7 @@ // and eventually they all become too large to inline, rather than // incrementally maknig a single function grow in a super linear fashion. std::unique_ptr>> Calls; - if (InlineEnablePriorityOrder) + if (!InlineEnablePriorityOrder) Calls = std::make_unique(); else Calls = std::make_unique>>();