aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-22 13:28:07 -0700
committerFangrui Song <i@maskray.me>2024-06-22 13:28:07 -0700
commitc9f6a5e49519f860f20f808b1af84dc3fc50ff91 (patch)
treee21ce2769219b4b51fb1b70b716ea7e912613638
parent8cb6e587fd40b97983e445ee3f17f4c6d7190df7 (diff)
downloadllvm-c9f6a5e49519f860f20f808b1af84dc3fc50ff91.zip
llvm-c9f6a5e49519f860f20f808b1af84dc3fc50ff91.tar.gz
llvm-c9f6a5e49519f860f20f808b1af84dc3fc50ff91.tar.bz2
[MC] Move computeBundlePadding closer to its only caller. NFC
There is only one caller after #95188.
-rw-r--r--llvm/include/llvm/MC/MCAssembler.h7
-rw-r--r--llvm/lib/MC/MCAssembler.cpp44
-rw-r--r--llvm/lib/MC/MCFragment.cpp41
3 files changed, 42 insertions, 50 deletions
diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h
index 914c750..5cf6459 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -500,13 +500,6 @@ public:
void dump() const;
};
-/// Compute the amount of padding required before the fragment \p F to
-/// obey bundling restrictions, where \p FOffset is the fragment's offset in
-/// its section and \p FSize is the fragment's size.
-uint64_t computeBundlePadding(const MCAssembler &Assembler,
- const MCEncodedFragment *F, uint64_t FOffset,
- uint64_t FSize);
-
} // end namespace llvm
#endif // LLVM_MC_MCASSEMBLER_H
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 671f6f7..fe0419b 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -403,6 +403,46 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
llvm_unreachable("invalid fragment kind");
}
+// Compute the amount of padding required before the fragment \p F to
+// obey bundling restrictions, where \p FOffset is the fragment's offset in
+// its section and \p FSize is the fragment's size.
+static uint64_t computeBundlePadding(unsigned BundleSize,
+ const MCEncodedFragment *F,
+ uint64_t FOffset, uint64_t FSize) {
+ uint64_t OffsetInBundle = FOffset & (BundleSize - 1);
+ uint64_t EndOfFragment = OffsetInBundle + FSize;
+
+ // There are two kinds of bundling restrictions:
+ //
+ // 1) For alignToBundleEnd(), add padding to ensure that the fragment will
+ // *end* on a bundle boundary.
+ // 2) Otherwise, check if the fragment would cross a bundle boundary. If it
+ // would, add padding until the end of the bundle so that the fragment
+ // will start in a new one.
+ if (F->alignToBundleEnd()) {
+ // Three possibilities here:
+ //
+ // A) The fragment just happens to end at a bundle boundary, so we're good.
+ // B) The fragment ends before the current bundle boundary: pad it just
+ // enough to reach the boundary.
+ // C) The fragment ends after the current bundle boundary: pad it until it
+ // reaches the end of the next bundle boundary.
+ //
+ // Note: this code could be made shorter with some modulo trickery, but it's
+ // intentionally kept in its more explicit form for simplicity.
+ if (EndOfFragment == BundleSize)
+ return 0;
+ else if (EndOfFragment < BundleSize)
+ return BundleSize - EndOfFragment;
+ else { // EndOfFragment > BundleSize
+ return 2 * BundleSize - EndOfFragment;
+ }
+ } else if (OffsetInBundle > 0 && EndOfFragment > BundleSize)
+ return BundleSize - OffsetInBundle;
+ else
+ return 0;
+}
+
void MCAsmLayout::layoutBundle(MCFragment *Prev, MCFragment *F) {
// If bundling is enabled and this fragment has instructions in it, it has to
// obey the bundling restrictions. With padding, we'll have:
@@ -433,8 +473,8 @@ void MCAsmLayout::layoutBundle(MCFragment *Prev, MCFragment *F) {
if (FSize > Assembler.getBundleAlignSize())
report_fatal_error("Fragment can't be larger than a bundle size");
- uint64_t RequiredBundlePadding =
- computeBundlePadding(Assembler, EF, EF->Offset, FSize);
+ uint64_t RequiredBundlePadding = computeBundlePadding(
+ Assembler.getBundleAlignSize(), EF, EF->Offset, FSize);
if (RequiredBundlePadding > UINT8_MAX)
report_fatal_error("Padding cannot exceed 255 bytes");
EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
diff --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp
index b1ed594..9e9a03a 100644
--- a/llvm/lib/MC/MCFragment.cpp
+++ b/llvm/lib/MC/MCFragment.cpp
@@ -155,47 +155,6 @@ uint64_t MCAsmLayout::getSectionFileSize(const MCSection *Sec) const {
return getSectionAddressSize(Sec);
}
-uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler,
- const MCEncodedFragment *F,
- uint64_t FOffset, uint64_t FSize) {
- uint64_t BundleSize = Assembler.getBundleAlignSize();
- assert(BundleSize > 0 &&
- "computeBundlePadding should only be called if bundling is enabled");
- uint64_t BundleMask = BundleSize - 1;
- uint64_t OffsetInBundle = FOffset & BundleMask;
- uint64_t EndOfFragment = OffsetInBundle + FSize;
-
- // There are two kinds of bundling restrictions:
- //
- // 1) For alignToBundleEnd(), add padding to ensure that the fragment will
- // *end* on a bundle boundary.
- // 2) Otherwise, check if the fragment would cross a bundle boundary. If it
- // would, add padding until the end of the bundle so that the fragment
- // will start in a new one.
- if (F->alignToBundleEnd()) {
- // Three possibilities here:
- //
- // A) The fragment just happens to end at a bundle boundary, so we're good.
- // B) The fragment ends before the current bundle boundary: pad it just
- // enough to reach the boundary.
- // C) The fragment ends after the current bundle boundary: pad it until it
- // reaches the end of the next bundle boundary.
- //
- // Note: this code could be made shorter with some modulo trickery, but it's
- // intentionally kept in its more explicit form for simplicity.
- if (EndOfFragment == BundleSize)
- return 0;
- else if (EndOfFragment < BundleSize)
- return BundleSize - EndOfFragment;
- else { // EndOfFragment > BundleSize
- return 2 * BundleSize - EndOfFragment;
- }
- } else if (OffsetInBundle > 0 && EndOfFragment > BundleSize)
- return BundleSize - OffsetInBundle;
- else
- return 0;
-}
-
/* *** */
MCFragment::MCFragment(FragmentType Kind, bool HasInstructions)