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

Liqiang TAO via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 07:00:51 PDT 2023


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

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.

>From 8ba49949cfbeda7ad9bccd7231f8154c5281603a Mon Sep 17 00:00:00 2001
From: Liqiang Tao <taolq at outlook.com>
Date: Mon, 16 Oct 2023 21:53:16 +0800
Subject: [PATCH] use std::make_heap to construct the heap after element
 updated

---
 llvm/lib/Analysis/InlineOrder.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

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



More information about the llvm-commits mailing list