diff options
author | Amir Ayupov <aaupov@fb.com> | 2024-01-18 19:59:09 -0800 |
---|---|---|
committer | Amir Ayupov <aaupov@fb.com> | 2024-01-18 19:59:09 -0800 |
commit | 9fec33aadc56c8c4ad3778a92dc0aaa3201a63ae (patch) | |
tree | 4f3bea9b1b20a36bb0ee374a6fca3b0987ec00c8 /llvm/lib/MC/MCAssembler.cpp | |
parent | 82bc33ea3f1a539be50ed46919dc53fc6b685da9 (diff) | |
download | llvm-9fec33aadc56c8c4ad3778a92dc0aaa3201a63ae.zip llvm-9fec33aadc56c8c4ad3778a92dc0aaa3201a63ae.tar.gz llvm-9fec33aadc56c8c4ad3778a92dc0aaa3201a63ae.tar.bz2 |
Revert "[BOLT] Fix unconditional output of boltedcollection in merge-fdata (#78653)"
This reverts commit 82bc33ea3f1a539be50ed46919dc53fc6b685da9.
Accidentally pushed unrelated changes.
Diffstat (limited to 'llvm/lib/MC/MCAssembler.cpp')
-rw-r--r-- | llvm/lib/MC/MCAssembler.cpp | 118 |
1 files changed, 37 insertions, 81 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 62baeb9..ad30b5c 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -298,43 +298,6 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout, const MCFixup &Fixup, return IsResolved; } -/// Check if the branch crosses the boundary. -/// -/// \param StartAddr start address of the fused/unfused branch. -/// \param Size size of the fused/unfused branch. -/// \param BoundaryAlignment alignment requirement of the branch. -/// \returns true if the branch cross the boundary. -static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size, - Align BoundaryAlignment) { - uint64_t EndAddr = StartAddr + Size; - return (StartAddr >> Log2(BoundaryAlignment)) != - ((EndAddr - 1) >> Log2(BoundaryAlignment)); -} - -/// Check if the branch is against the boundary. -/// -/// \param StartAddr start address of the fused/unfused branch. -/// \param Size size of the fused/unfused branch. -/// \param BoundaryAlignment alignment requirement of the branch. -/// \returns true if the branch is against the boundary. -static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size, - Align BoundaryAlignment) { - uint64_t EndAddr = StartAddr + Size; - return (EndAddr & (BoundaryAlignment.value() - 1)) == 0; -} - -/// Check if the branch needs padding. -/// -/// \param StartAddr start address of the fused/unfused branch. -/// \param Size size of the fused/unfused branch. -/// \param BoundaryAlignment alignment requirement of the branch. -/// \returns true if the branch needs padding. -static bool needPadding(uint64_t StartAddr, uint64_t Size, - Align BoundaryAlignment) { - return mayCrossBoundary(StartAddr, Size, BoundaryAlignment) || - isAgainstBoundary(StartAddr, Size, BoundaryAlignment); -} - uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, const MCFragment &F) const { assert(getBackendPtr() && "Requires assembler backend"); @@ -395,41 +358,6 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, return Size; } - case MCFragment::FT_NeverAlign: { - // Disclaimer: NeverAlign fragment size depends on the size of its immediate - // successor, but NeverAlign need not be a MCRelaxableFragment. - // NeverAlign fragment size is recomputed if the successor is relaxed: - // - If RelaxableFragment is relaxed, it gets invalidated by marking its - // predecessor as LastValidFragment. - // - This forces the assembler to call MCAsmLayout::layoutFragment on that - // relaxable fragment, which in turn will always ask the predecessor to - // compute its size (see "computeFragmentSize(prev)" in layoutFragment). - // - // In short, the simplest way to ensure that computeFragmentSize() is sane - // is to establish the following rule: it should never examine fragments - // after the current fragment in the section. If we logically need to - // examine any fragment after the current fragment, we need to do that using - // relaxation, inside MCAssembler::layoutSectionOnce. - const MCNeverAlignFragment &NAF = cast<MCNeverAlignFragment>(F); - const MCFragment *NF = F.getNextNode(); - uint64_t Offset = Layout.getFragmentOffset(&NAF); - size_t NextFragSize = 0; - if (const auto *NextFrag = dyn_cast<MCRelaxableFragment>(NF)) { - NextFragSize = NextFrag->getContents().size(); - } else if (const auto *NextFrag = dyn_cast<MCDataFragment>(NF)) { - NextFragSize = NextFrag->getContents().size(); - } else { - llvm_unreachable("Didn't find the expected fragment after NeverAlign"); - } - // Check if the next fragment ends at the alignment we want to avoid. - if (isAgainstBoundary(Offset, NextFragSize, Align(NAF.getAlignment()))) { - // Avoid this alignment by introducing minimum nop. - assert(getBackend().getMinimumNopSize() != NAF.getAlignment()); - return getBackend().getMinimumNopSize(); - } - return 0; - } - case MCFragment::FT_Org: { const MCOrgFragment &OF = cast<MCOrgFragment>(F); MCValue Value; @@ -653,15 +581,6 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm, break; } - case MCFragment::FT_NeverAlign: { - const MCNeverAlignFragment &NAF = cast<MCNeverAlignFragment>(F); - if (!Asm.getBackend().writeNopData(OS, FragmentSize, - &NAF.getSubtargetInfo())) - report_fatal_error("unable to write nop sequence of " + - Twine(FragmentSize) + " bytes"); - break; - } - case MCFragment::FT_Data: ++stats::EmittedDataFragments; OS << cast<MCDataFragment>(F).getContents(); @@ -1133,6 +1052,43 @@ bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) { return OldSize != LF.getContents().size(); } +/// Check if the branch crosses the boundary. +/// +/// \param StartAddr start address of the fused/unfused branch. +/// \param Size size of the fused/unfused branch. +/// \param BoundaryAlignment alignment requirement of the branch. +/// \returns true if the branch cross the boundary. +static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size, + Align BoundaryAlignment) { + uint64_t EndAddr = StartAddr + Size; + return (StartAddr >> Log2(BoundaryAlignment)) != + ((EndAddr - 1) >> Log2(BoundaryAlignment)); +} + +/// Check if the branch is against the boundary. +/// +/// \param StartAddr start address of the fused/unfused branch. +/// \param Size size of the fused/unfused branch. +/// \param BoundaryAlignment alignment requirement of the branch. +/// \returns true if the branch is against the boundary. +static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size, + Align BoundaryAlignment) { + uint64_t EndAddr = StartAddr + Size; + return (EndAddr & (BoundaryAlignment.value() - 1)) == 0; +} + +/// Check if the branch needs padding. +/// +/// \param StartAddr start address of the fused/unfused branch. +/// \param Size size of the fused/unfused branch. +/// \param BoundaryAlignment alignment requirement of the branch. +/// \returns true if the branch needs padding. +static bool needPadding(uint64_t StartAddr, uint64_t Size, + Align BoundaryAlignment) { + return mayCrossBoundary(StartAddr, Size, BoundaryAlignment) || + isAgainstBoundary(StartAddr, Size, BoundaryAlignment); +} + bool MCAssembler::relaxBoundaryAlign(MCAsmLayout &Layout, MCBoundaryAlignFragment &BF) { // BoundaryAlignFragment that doesn't need to align any fragment should not be |