Skip to content

Commit 629b6f4

Browse files
authored
[BOLT][NFC] Extend updateLayoutIndices (#93861)
Make FunctionLayout::updateLayoutIndices const and add an overloaded function that updates LayoutIndices given an Order parameter.
1 parent 90acfbf commit 629b6f4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

bolt/include/bolt/Core/FunctionLayout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ class FunctionLayout {
213213
void eraseBasicBlocks(const DenseSet<const BinaryBasicBlock *> ToErase);
214214

215215
/// Make sure fragments' and basic blocks' indices match the current layout.
216-
void updateLayoutIndices();
216+
void updateLayoutIndices() const;
217+
void updateLayoutIndices(ArrayRef<BinaryBasicBlock *> Order) const;
217218

218219
/// Replace the current layout with NewLayout. Uses the block's
219220
/// self-identifying fragment number to assign blocks to infer function

bolt/lib/Core/FunctionLayout.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,20 @@ void FunctionLayout::eraseBasicBlocks(
164164
updateLayoutIndices();
165165
}
166166

167-
void FunctionLayout::updateLayoutIndices() {
167+
void FunctionLayout::updateLayoutIndices() const {
168168
unsigned BlockIndex = 0;
169-
for (FunctionFragment &FF : fragments()) {
169+
for (const FunctionFragment &FF : fragments()) {
170170
for (BinaryBasicBlock *const BB : FF) {
171171
BB->setLayoutIndex(BlockIndex++);
172172
BB->setFragmentNum(FF.getFragmentNum());
173173
}
174174
}
175175
}
176+
void FunctionLayout::updateLayoutIndices(
177+
ArrayRef<BinaryBasicBlock *> Order) const {
178+
for (auto [Index, BB] : llvm::enumerate(Order))
179+
BB->setLayoutIndex(Index);
180+
}
176181

177182
bool FunctionLayout::update(const ArrayRef<BinaryBasicBlock *> NewLayout) {
178183
const bool EqualBlockOrder = llvm::equal(Blocks, NewLayout);

0 commit comments

Comments
 (0)