[llvm] [ModuleInliner] use std::make_heap to construct the heap after element updated (PR #69206)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 07:02:08 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Liqiang TAO (taoliq)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/69206.diff


1 Files Affected:

- (modified) llvm/lib/Analysis/InlineOrder.cpp (+4-5) 


``````````diff
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);
     }
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/69206


More information about the llvm-commits mailing list