[llvm] [BOLT][NFC] Make const & overload updateLayoutIndices (PR #93861)

shaw young via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 11:53:06 PDT 2024


https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/93861

Make FunctionLayout::updateLayoutIndices const and add an overloaded function that updates LayoutIndices given some Order parameter


>From 388bed148b825ea2db279cc8ab1325a39c64dbe1 Mon Sep 17 00:00:00 2001
From: shawbyoung <shawbyoung at gmail.com>
Date: Thu, 30 May 2024 11:42:21 -0700
Subject: [PATCH] [BOLT][NFC] Make const & overload updateLayoutIndices

---
 bolt/include/bolt/Core/FunctionLayout.h | 3 ++-
 bolt/lib/Core/FunctionLayout.cpp        | 9 +++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/bolt/include/bolt/Core/FunctionLayout.h b/bolt/include/bolt/Core/FunctionLayout.h
index b685a99c79c14..6a13cbec69fee 100644
--- a/bolt/include/bolt/Core/FunctionLayout.h
+++ b/bolt/include/bolt/Core/FunctionLayout.h
@@ -213,7 +213,8 @@ class FunctionLayout {
   void eraseBasicBlocks(const DenseSet<const BinaryBasicBlock *> ToErase);
 
   /// Make sure fragments' and basic blocks' indices match the current layout.
-  void updateLayoutIndices();
+  void updateLayoutIndices() const;
+  void updateLayoutIndices(ArrayRef<BinaryBasicBlock *> Order) const;
 
   /// Replace the current layout with NewLayout. Uses the block's
   /// self-identifying fragment number to assign blocks to infer function
diff --git a/bolt/lib/Core/FunctionLayout.cpp b/bolt/lib/Core/FunctionLayout.cpp
index 73f4d5247d9ac..15e6127ad2e9e 100644
--- a/bolt/lib/Core/FunctionLayout.cpp
+++ b/bolt/lib/Core/FunctionLayout.cpp
@@ -164,15 +164,20 @@ void FunctionLayout::eraseBasicBlocks(
   updateLayoutIndices();
 }
 
-void FunctionLayout::updateLayoutIndices() {
+void FunctionLayout::updateLayoutIndices() const {
   unsigned BlockIndex = 0;
-  for (FunctionFragment &FF : fragments()) {
+  for (const FunctionFragment &FF : fragments()) {
     for (BinaryBasicBlock *const BB : FF) {
       BB->setLayoutIndex(BlockIndex++);
       BB->setFragmentNum(FF.getFragmentNum());
     }
   }
 }
+void FunctionLayout::updateLayoutIndices(
+    ArrayRef<BinaryBasicBlock *> Order) const {
+  for (auto [Index, BB] : llvm::enumerate(Order))
+    BB->setLayoutIndex(Index);
+}
 
 bool FunctionLayout::update(const ArrayRef<BinaryBasicBlock *> NewLayout) {
   const bool EqualBlockOrder = llvm::equal(Blocks, NewLayout);



More information about the llvm-commits mailing list