This patch makes PriorityInlineOrder lazily updated.
The PriorityInlineOrder would lazily update the desirability of a call site if it's decreasing.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Transforms/IPO/Inliner.cpp | ||
---|---|---|
732–737 | Could we split this function into two like so? // 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); } The reason I am suggesting this is that the current implementation of cmp encapsulates two things -- the order of arguments dictated by std::make_heap and our logic about which one is more desirable. By hiding > inside isMoreDesirable, the reader doesn't have to worry about whether this metric is "the higher the better" or "the lower the better". See below for an additional use of isMoreDesirable. | |
749 | For simplicity | |
757 | I'd say: Changed = isMoreDesirable(PreviousGoodness, CurrentGoodness); This way, we don't express the comparison operator < at multiple places, making it easier to try other cost metrics. | |
856 | Do you really mean to put ! here? |
llvm/lib/Transforms/IPO/Inliner.cpp | ||
---|---|---|
856 | Oh, I forgot to remove the hard code for testing. |
How do you think about:
T pop() { if (!initialized) { make_heap ... initialized = true; } } // same as front
It seems simple and cheaper.
Another option is:
SmallVector<CallBase*> CallSites; // Fill CallSites if (InlineEnablePriorityOrder) Calls = std::make_unique<PriorityInlineOrder>(CallSites); // Do make heap here else Calls = std::make_unique<InlinerOrder>(CallSites);
It looks good too.
llvm/lib/Transforms/IPO/Inliner.cpp | ||
---|---|---|
732–737 | This refactoring is sexy. I love it! Thanks a lot. |
I think this if branch is not necessary. Because whenever pop() is called, the heap inside is maintained.
So there is not necessary to do that.
Another option is:
SmallVector<CallBase*> CallSites; // Fill CallSites if (InlineEnablePriorityOrder) Calls = std::make_unique<PriorityInlineOrder>(CallSites); // Do make heap here else Calls = std::make_unique<InlinerOrder>(CallSites);It looks good too.
Since this class is only used here, we could keep it minimal, no need to consider the generality.
Even without this construct methrod, it could work.
(Maybe I made some misunderstanding. The lazily update is for the priority of the call site which is pushed in heap,
not for the heap. The heap is already well maintained.
Could we split this function into two like so?
The reason I am suggesting this is that the current implementation of cmp encapsulates two things -- the order of arguments dictated by std::make_heap and our logic about which one is more desirable.
By hiding > inside isMoreDesirable, the reader doesn't have to worry about whether this metric is "the higher the better" or "the lower the better".
See below for an additional use of isMoreDesirable.