Skip to content

Commit c9f6a5e

Browse files
committed
[MC] Move computeBundlePadding closer to its only caller. NFC
There is only one caller after #95188.
1 parent 8cb6e58 commit c9f6a5e

File tree

3 files changed

+42
-50
lines changed

3 files changed

+42
-50
lines changed

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,6 @@ class MCAssembler {
500500
void dump() const;
501501
};
502502

503-
/// Compute the amount of padding required before the fragment \p F to
504-
/// obey bundling restrictions, where \p FOffset is the fragment's offset in
505-
/// its section and \p FSize is the fragment's size.
506-
uint64_t computeBundlePadding(const MCAssembler &Assembler,
507-
const MCEncodedFragment *F, uint64_t FOffset,
508-
uint64_t FSize);
509-
510503
} // end namespace llvm
511504

512505
#endif // LLVM_MC_MCASSEMBLER_H

llvm/lib/MC/MCAssembler.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,46 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
403403
llvm_unreachable("invalid fragment kind");
404404
}
405405

406+
// Compute the amount of padding required before the fragment \p F to
407+
// obey bundling restrictions, where \p FOffset is the fragment's offset in
408+
// its section and \p FSize is the fragment's size.
409+
static uint64_t computeBundlePadding(unsigned BundleSize,
410+
const MCEncodedFragment *F,
411+
uint64_t FOffset, uint64_t FSize) {
412+
uint64_t OffsetInBundle = FOffset & (BundleSize - 1);
413+
uint64_t EndOfFragment = OffsetInBundle + FSize;
414+
415+
// There are two kinds of bundling restrictions:
416+
//
417+
// 1) For alignToBundleEnd(), add padding to ensure that the fragment will
418+
// *end* on a bundle boundary.
419+
// 2) Otherwise, check if the fragment would cross a bundle boundary. If it
420+
// would, add padding until the end of the bundle so that the fragment
421+
// will start in a new one.
422+
if (F->alignToBundleEnd()) {
423+
// Three possibilities here:
424+
//
425+
// A) The fragment just happens to end at a bundle boundary, so we're good.
426+
// B) The fragment ends before the current bundle boundary: pad it just
427+
// enough to reach the boundary.
428+
// C) The fragment ends after the current bundle boundary: pad it until it
429+
// reaches the end of the next bundle boundary.
430+
//
431+
// Note: this code could be made shorter with some modulo trickery, but it's
432+
// intentionally kept in its more explicit form for simplicity.
433+
if (EndOfFragment == BundleSize)
434+
return 0;
435+
else if (EndOfFragment < BundleSize)
436+
return BundleSize - EndOfFragment;
437+
else { // EndOfFragment > BundleSize
438+
return 2 * BundleSize - EndOfFragment;
439+
}
440+
} else if (OffsetInBundle > 0 && EndOfFragment > BundleSize)
441+
return BundleSize - OffsetInBundle;
442+
else
443+
return 0;
444+
}
445+
406446
void MCAsmLayout::layoutBundle(MCFragment *Prev, MCFragment *F) {
407447
// If bundling is enabled and this fragment has instructions in it, it has to
408448
// obey the bundling restrictions. With padding, we'll have:
@@ -433,8 +473,8 @@ void MCAsmLayout::layoutBundle(MCFragment *Prev, MCFragment *F) {
433473
if (FSize > Assembler.getBundleAlignSize())
434474
report_fatal_error("Fragment can't be larger than a bundle size");
435475

436-
uint64_t RequiredBundlePadding =
437-
computeBundlePadding(Assembler, EF, EF->Offset, FSize);
476+
uint64_t RequiredBundlePadding = computeBundlePadding(
477+
Assembler.getBundleAlignSize(), EF, EF->Offset, FSize);
438478
if (RequiredBundlePadding > UINT8_MAX)
439479
report_fatal_error("Padding cannot exceed 255 bytes");
440480
EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));

llvm/lib/MC/MCFragment.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -155,47 +155,6 @@ uint64_t MCAsmLayout::getSectionFileSize(const MCSection *Sec) const {
155155
return getSectionAddressSize(Sec);
156156
}
157157

158-
uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler,
159-
const MCEncodedFragment *F,
160-
uint64_t FOffset, uint64_t FSize) {
161-
uint64_t BundleSize = Assembler.getBundleAlignSize();
162-
assert(BundleSize > 0 &&
163-
"computeBundlePadding should only be called if bundling is enabled");
164-
uint64_t BundleMask = BundleSize - 1;
165-
uint64_t OffsetInBundle = FOffset & BundleMask;
166-
uint64_t EndOfFragment = OffsetInBundle + FSize;
167-
168-
// There are two kinds of bundling restrictions:
169-
//
170-
// 1) For alignToBundleEnd(), add padding to ensure that the fragment will
171-
// *end* on a bundle boundary.
172-
// 2) Otherwise, check if the fragment would cross a bundle boundary. If it
173-
// would, add padding until the end of the bundle so that the fragment
174-
// will start in a new one.
175-
if (F->alignToBundleEnd()) {
176-
// Three possibilities here:
177-
//
178-
// A) The fragment just happens to end at a bundle boundary, so we're good.
179-
// B) The fragment ends before the current bundle boundary: pad it just
180-
// enough to reach the boundary.
181-
// C) The fragment ends after the current bundle boundary: pad it until it
182-
// reaches the end of the next bundle boundary.
183-
//
184-
// Note: this code could be made shorter with some modulo trickery, but it's
185-
// intentionally kept in its more explicit form for simplicity.
186-
if (EndOfFragment == BundleSize)
187-
return 0;
188-
else if (EndOfFragment < BundleSize)
189-
return BundleSize - EndOfFragment;
190-
else { // EndOfFragment > BundleSize
191-
return 2 * BundleSize - EndOfFragment;
192-
}
193-
} else if (OffsetInBundle > 0 && EndOfFragment > BundleSize)
194-
return BundleSize - OffsetInBundle;
195-
else
196-
return 0;
197-
}
198-
199158
/* *** */
200159

201160
MCFragment::MCFragment(FragmentType Kind, bool HasInstructions)

0 commit comments

Comments
 (0)