diff options
author | Peter Smith <peter.smith@linaro.org> | 2018-06-15 09:48:18 +0000 |
---|---|---|
committer | Peter Smith <peter.smith@linaro.org> | 2018-06-15 09:48:18 +0000 |
commit | 1503fc0fd018ad30e02bb8c880330a2e351e4e76 (patch) | |
tree | 688756e1c629d0a594bf82223df4c26be422e4e4 /llvm/lib/MC | |
parent | 205276bf37dc1e482e5d2d1ff5a9537aa4eb797f (diff) | |
download | bcm5719-llvm-1503fc0fd018ad30e02bb8c880330a2e351e4e76.tar.gz bcm5719-llvm-1503fc0fd018ad30e02bb8c880330a2e351e4e76.zip |
[MC] Move bundling and MCSubtargetInfo to MCEncodedFragment [NFC]
Instruction bundling is only supported on descendants of the
MCEncodedFragment type. By moving the bundling functionality and
MCSubtargetInfo to this class it makes it easier to set and extract the
MCSubtargetInfo when it is necessary.
This is a refactoring change that will make it easier to pass the
MCSubtargetInfo through to writeNops when nop padding is required.
Differential Revision: https://reviews.llvm.org/D45959
llvm-svn: 334814
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/MCAssembler.cpp | 27 | ||||
-rw-r--r-- | llvm/lib/MC/MCELFStreamer.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/MC/MCFragment.cpp | 18 |
3 files changed, 25 insertions, 21 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 973311c93f6..1470e026d98 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -426,17 +426,18 @@ void MCAsmLayout::layoutFragment(MCFragment *F) { if (Assembler.isBundlingEnabled() && F->hasInstructions()) { assert(isa<MCEncodedFragment>(F) && "Only MCEncodedFragment implementations have instructions"); - uint64_t FSize = Assembler.computeFragmentSize(*this, *F); + MCEncodedFragment *EF = cast<MCEncodedFragment>(F); + uint64_t FSize = Assembler.computeFragmentSize(*this, *EF); if (!Assembler.getRelaxAll() && FSize > Assembler.getBundleAlignSize()) report_fatal_error("Fragment can't be larger than a bundle size"); - uint64_t RequiredBundlePadding = computeBundlePadding(Assembler, F, - F->Offset, FSize); + uint64_t RequiredBundlePadding = + computeBundlePadding(Assembler, EF, EF->Offset, FSize); if (RequiredBundlePadding > UINT8_MAX) report_fatal_error("Padding cannot exceed 255 bytes"); - F->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding)); - F->Offset += RequiredBundlePadding; + EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding)); + EF->Offset += RequiredBundlePadding; } } @@ -450,19 +451,20 @@ void MCAssembler::registerSymbol(const MCSymbol &Symbol, bool *Created) { } } -void MCAssembler::writeFragmentPadding(raw_ostream &OS, const MCFragment &F, +void MCAssembler::writeFragmentPadding(raw_ostream &OS, + const MCEncodedFragment &EF, uint64_t FSize) const { assert(getBackendPtr() && "Expected assembler backend"); // Should NOP padding be written out before this fragment? - unsigned BundlePadding = F.getBundlePadding(); + unsigned BundlePadding = EF.getBundlePadding(); if (BundlePadding > 0) { assert(isBundlingEnabled() && "Writing bundle padding with disabled bundling"); - assert(F.hasInstructions() && + assert(EF.hasInstructions() && "Writing bundle padding for a fragment without instructions"); unsigned TotalLength = BundlePadding + static_cast<unsigned>(FSize); - if (F.alignToBundleEnd() && TotalLength > getBundleAlignSize()) { + if (EF.alignToBundleEnd() && TotalLength > getBundleAlignSize()) { // If the padding itself crosses a bundle boundary, it must be emitted // in 2 pieces, since even nop instructions must not cross boundaries. // v--------------v <- BundleAlignSize @@ -473,8 +475,8 @@ void MCAssembler::writeFragmentPadding(raw_ostream &OS, const MCFragment &F, // ^-------------------^ <- TotalLength unsigned DistanceToBoundary = TotalLength - getBundleAlignSize(); if (!getBackend().writeNopData(OS, DistanceToBoundary)) - report_fatal_error("unable to write NOP sequence of " + - Twine(DistanceToBoundary) + " bytes"); + report_fatal_error("unable to write NOP sequence of " + + Twine(DistanceToBoundary) + " bytes"); BundlePadding -= DistanceToBoundary; } if (!getBackend().writeNopData(OS, BundlePadding)) @@ -491,7 +493,8 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm, support::endianness Endian = Asm.getBackend().Endian; - Asm.writeFragmentPadding(OS, F, FragmentSize); + if (const MCEncodedFragment *EF = dyn_cast<MCEncodedFragment>(&F)) + Asm.writeFragmentPadding(OS, *EF, FragmentSize); // This variable (and its dummy usage) is to participate in the assert at // the end of the function. diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index df11495a954..f44d877e260 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -557,6 +557,7 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst, MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment(); insert(CEIF); CEIF->getContents().append(Code.begin(), Code.end()); + CEIF->setHasInstructions(STI); return; } else { DF = new MCDataFragment(); diff --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp index 70118f9c371..01ad640ee22 100644 --- a/llvm/lib/MC/MCFragment.cpp +++ b/llvm/lib/MC/MCFragment.cpp @@ -189,7 +189,7 @@ uint64_t MCAsmLayout::getSectionFileSize(const MCSection *Sec) const { } uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler, - const MCFragment *F, + const MCEncodedFragment *F, uint64_t FOffset, uint64_t FSize) { uint64_t BundleSize = Assembler.getBundleAlignSize(); assert(BundleSize > 0 && @@ -236,10 +236,9 @@ void ilist_alloc_traits<MCFragment>::deleteNode(MCFragment *V) { V->destroy(); } MCFragment::~MCFragment() = default; MCFragment::MCFragment(FragmentType Kind, bool HasInstructions, - uint8_t BundlePadding, MCSection *Parent) - : Kind(Kind), HasInstructions(HasInstructions), AlignToBundleEnd(false), - BundlePadding(BundlePadding), Parent(Parent), Atom(nullptr), - Offset(~UINT64_C(0)) { + MCSection *Parent) + : Kind(Kind), HasInstructions(HasInstructions), Parent(Parent), + Atom(nullptr), Offset(~UINT64_C(0)) { if (Parent && !isDummy()) Parent->getFragmentList().push_back(this); } @@ -333,10 +332,11 @@ LLVM_DUMP_METHOD void MCFragment::dump() const { case MCFragment::FT_Dummy: OS << "MCDummyFragment"; break; } - OS << "<MCFragment " << (const void*) this << " LayoutOrder:" << LayoutOrder - << " Offset:" << Offset - << " HasInstructions:" << hasInstructions() - << " BundlePadding:" << static_cast<unsigned>(getBundlePadding()) << ">"; + OS << "<MCFragment " << (const void *)this << " LayoutOrder:" << LayoutOrder + << " Offset:" << Offset << " HasInstructions:" << hasInstructions(); + if (const MCEncodedFragment *EF = cast<MCEncodedFragment>(this)) + OS << " BundlePadding:" << static_cast<unsigned>(EF->getBundlePadding()); + OS << ">"; switch (getKind()) { case MCFragment::FT_Align: { |