[PATCH] D104654: make PrioriInlineOrder lazily updated
Liqiang Tao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 21 09:07:05 PDT 2021
taolq created this revision.
Herald added subscribers: ChuanqiXu, ormris, hiraditya, eraman.
taolq requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104654
Files:
llvm/lib/Transforms/IPO/Inliner.cpp
Index: llvm/lib/Transforms/IPO/Inliner.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Inliner.cpp
+++ 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<InlineOrder<std::pair<CallBase *, int>>> Calls;
- if (InlineEnablePriorityOrder)
+ if (!InlineEnablePriorityOrder)
Calls = std::make_unique<PriorityInlineOrder>();
else
Calls = std::make_unique<DefaultInlineOrder<std::pair<CallBase *, int>>>();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104654.353391.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210621/cc0deeb4/attachment.bin>
More information about the llvm-commits
mailing list