Skip to content

[BOLT][NFC] Extend updateLayoutIndices #93861

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

shawbyoung
Copy link
Contributor

@shawbyoung shawbyoung commented May 30, 2024

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

@llvmbot
Copy link
Member

llvmbot commented May 30, 2024

@llvm/pr-subscribers-bolt

Author: shaw young (shawbyoung)

Changes

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


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

2 Files Affected:

  • (modified) bolt/include/bolt/Core/FunctionLayout.h (+2-1)
  • (modified) bolt/lib/Core/FunctionLayout.cpp (+7-2)
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);

@shawbyoung shawbyoung changed the title [BOLT][NFC] Make const & overload updateLayoutIndices [BOLT][NFC] Extend updateLayoutIndices May 30, 2024
@aaupov aaupov merged commit 629b6f4 into llvm:main May 30, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants