-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[ModuleInliner] use std::make_heap to construct the heap after element updated #69206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-analysis Author: Liqiang TAO (taoliq) ChangesAfter Full diff: https://github.com/llvm/llvm-project/pull/69206.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/InlineOrder.cpp b/llvm/lib/Analysis/InlineOrder.cpp
index 503880e3e8f0e93..98dea4846ec1103 100644
--- a/llvm/lib/Analysis/InlineOrder.cpp
+++ b/llvm/lib/Analysis/InlineOrder.cpp
@@ -219,13 +219,12 @@ class PriorityInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
// 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.
+ // the desirability of the front call site decreases, the heap is re-constructed
+ // by std::make_heap. For simplicity, those cases where the desirability of
+ // a call site increases are ignored here.
void adjust() {
while (updateAndCheckDecreased(Heap.front())) {
- std::pop_heap(Heap.begin(), Heap.end(), isLess);
- std::push_heap(Heap.begin(), Heap.end(), isLess);
+ std::make_heap(Heap.begin(), Heap.end(), isLess);
}
}
|
You can test this locally with the following command:git-clang-format --diff f41ec27f7eba34548a280a4a4d7de2ef32837210 8ba49949cfbeda7ad9bccd7231f8154c5281603a -- llvm/lib/Analysis/InlineOrder.cpp View the diff from clang-format here.diff --git a/llvm/lib/Analysis/InlineOrder.cpp b/llvm/lib/Analysis/InlineOrder.cpp
index 98dea4846..5280f100e 100644
--- a/llvm/lib/Analysis/InlineOrder.cpp
+++ b/llvm/lib/Analysis/InlineOrder.cpp
@@ -219,9 +219,9 @@ class PriorityInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
// 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, the heap is re-constructed
- // by std::make_heap. For simplicity, those cases where the desirability of
- // a call site increases are ignored here.
+ // the desirability of the front call site decreases, the heap is
+ // re-constructed by std::make_heap. For simplicity, those cases where the
+ // desirability of a call site increases are ignored here.
void adjust() {
while (updateAndCheckDecreased(Heap.front())) {
std::make_heap(Heap.begin(), Heap.end(), isLess);
|
Hmm. |
@taoliq, the following seems to work even with the expensive checks enabled. I'll post this as separate PR myself:
Although The code snippet above:
In other words, we use the last element as a safe work area while we are updating its priority. We could reduce the number of calls to |
I've posted #69251 as an alternative fix. |
Thanks Kazu. I like your fix, so I'd like to close this one. |
After
updateAndCheckDecreased
, some element may be updated and the range(Heap.begin(), Heap.end()) is not a valid heap.Use std::make_heap to make sure the heap is valid.