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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bolt/include/bolt/Core/FunctionLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions bolt/lib/Core/FunctionLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading