[PATCH] D104654: [llvm][Inliner] Make PriorityInlineOrder lazily updated
Liqiang Tao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 22 18:01:02 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0d96fdd3a4c: [llvm][Inliner] Make PriorityInlineOrder lazily updated (authored by taolq).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104654/new/
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
@@ -729,13 +729,41 @@
using reference = T &;
using const_reference = const T &;
- static bool cmp(const T &P1, const T &P2) { return P1.second > P2.second; }
+ // Return true if S1 is more desirable than S2.
+ static bool isMoreDesirable(int S1, int S2) { return S1 < S2; }
+
+ static bool cmp(const T &P1, const T &P2) {
+ return isMoreDesirable(P2.second, P1.second);
+ }
int evaluate(CallBase *CB) {
Function *Callee = CB->getCalledFunction();
return (int)Callee->getInstructionCount();
}
+ // A call site could become less desirable for inlining because of the size
+ // growth from prior inlining into the callee. 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
+ // pushed right back into the heap. For simplicity, 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 = isMoreDesirable(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 +779,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 +791,8 @@
const_reference front() override {
assert(size() > 0);
+ adjust();
+
CallBase *CB = Heap.front().first;
return *InlineHistoryMap.find(CB);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104654.353835.patch
Type: text/x-patch
Size: 2239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210623/2c8a99a6/attachment.bin>
More information about the llvm-commits
mailing list