From 286c4dc355b8be6806081b23c3097485821c7642 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Wed, 12 Sep 2012 05:06:18 +0000 Subject: Release build: guard dump functions with "#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)" No functional change. Update r163344. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163679 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index e38bc45..d47b346 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -830,7 +830,7 @@ raw_ostream &operator<<(raw_ostream &OS, const MCFixup &AF) { } -#ifndef NDEBUG +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void MCFragment::dump() { raw_ostream &OS = llvm::errs(); -- cgit v1.1 From c5252da873d547a19069eaf9030fec203f128f66 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Fri, 14 Sep 2012 14:57:36 +0000 Subject: Fix Doxygen issues: * wrap code blocks in \code ... \endcode; * refer to parameter names in paragraphs correctly (\arg is not what most people want -- it starts a new paragraph); * use \param instead of \arg to document parameters in order to be consistent with the rest of the codebase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163902 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index d47b346..d2bf1ff 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -381,7 +381,7 @@ void MCAsmLayout::LayoutFragment(MCFragment *F) { LastValidFragment[F->getParent()] = F; } -/// WriteFragmentData - Write the \arg F data to the output file. +/// WriteFragmentData - Write the \p F data to the output file. static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment &F) { MCObjectWriter *OW = &Asm.getWriter(); -- cgit v1.1 From b5762bfd8cb8238ec34b0b422d074f65f35b8eab Mon Sep 17 00:00:00 2001 From: Jim Grosbach Date: Tue, 18 Sep 2012 23:05:18 +0000 Subject: Tidy up. Minor formatting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164182 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index d2bf1ff..726ec5a 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -199,8 +199,7 @@ MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_, MCCodeEmitter &Emitter_, MCObjectWriter &Writer_, raw_ostream &OS_) : Context(Context_), Backend(Backend_), Emitter(Emitter_), Writer(Writer_), - OS(OS_), RelaxAll(false), NoExecStack(false), SubsectionsViaSymbols(false) -{ + OS(OS_), RelaxAll(false), NoExecStack(false), SubsectionsViaSymbols(false) { } MCAssembler::~MCAssembler() { @@ -533,7 +532,7 @@ void MCAssembler::writeSectionData(const MCSectionData *SD, } uint64_t Start = getWriter().getStream().tell(); - (void) Start; + (void)Start; for (MCSectionData::const_iterator it = SD->begin(), ie = SD->end(); it != ie; ++it) -- cgit v1.1 From d04a8d4b33ff316ca4cf961e06c9e312eff8e64f Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 3 Dec 2012 16:50:05 +0000 Subject: Use the new script to sort the includes of every file under lib. Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169131 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 726ec5a..48aec66 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -9,25 +9,25 @@ #define DEBUG_TYPE "assembler" #include "llvm/MC/MCAssembler.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/Twine.h" +#include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCFixupKindInfo.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCValue.h" -#include "llvm/MC/MCDwarf.h" -#include "llvm/MC/MCAsmBackend.h" -#include "llvm/ADT/Statistic.h" -#include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/Twine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; -- cgit v1.1 From 5c10f509f45820d1198bfb975840e93a782745ac Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 5 Dec 2012 22:11:02 +0000 Subject: Change std::vector to SmallVector<4> and remove some unused methods. This is more consistent with other vectors in this code. In addition, I ran some tests compiling a large program and >96% of fragments have 4 or less fixups, so SmallVector<4> is a good optimization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169433 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 48aec66..457abd2 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -870,7 +870,7 @@ void MCFragment::dump() { } OS << "] (" << Contents.size() << " bytes)"; - if (!DF->getFixups().empty()) { + if (DF->fixup_begin() != DF->fixup_end()) { OS << ",\n "; OS << " Fixups:["; for (MCDataFragment::const_fixup_iterator it = DF->fixup_begin(), -- cgit v1.1 From 8ddc5a192935728c15602a4c15501e35f116422d Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Fri, 7 Dec 2012 17:59:21 +0000 Subject: Add separate statistics for Data and Inst fragments emitted during relaxation. Also fixes a test that was overly-sensitive to the exact order of statistics emitted. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169619 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 457abd2..5032e6f 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -33,7 +33,9 @@ using namespace llvm; namespace { namespace stats { -STATISTIC(EmittedFragments, "Number of emitted assembler fragments"); +STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total"); +STATISTIC(EmittedInstFragments, "Number of emitted assembler fragments - instruction"); +STATISTIC(EmittedDataFragments, "Number of emitted assembler fragments - data"); STATISTIC(evaluateFixup, "Number of evaluated fixups"); STATISTIC(FragmentLayouts, "Number of fragment layouts"); STATISTIC(ObjectBytes, "Number of emitted object file bytes"); @@ -432,6 +434,7 @@ static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout, } case MCFragment::FT_Data: { + ++stats::EmittedDataFragments; MCDataFragment &DF = cast(F); assert(FragmentSize == DF.getContents().size() && "Invalid size!"); OW->WriteBytes(DF.getContents().str()); @@ -456,6 +459,7 @@ static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout, } case MCFragment::FT_Inst: { + ++stats::EmittedInstFragments; MCInstFragment &IF = cast(F); OW->WriteBytes(StringRef(IF.getCode().begin(), IF.getCode().size())); break; -- cgit v1.1 From 64d9a3233476553fc950f0f2fc6a2cdd2a4c05cf Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Fri, 7 Dec 2012 19:13:57 +0000 Subject: Refactor MCInstFragment and MCDataFragment to adhere to a common interface, which removes code duplication and prepares the ground for future additions. Full discussion: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20121203/158233.html git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169626 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 75 +++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 5032e6f..b2136e5 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -168,6 +168,11 @@ MCFragment::MCFragment(FragmentType _Kind, MCSectionData *_Parent) /* *** */ +MCEncodedFragment::~MCEncodedFragment() { +} + +/* *** */ + MCSectionData::MCSectionData() : Section(0) {} MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A) @@ -382,9 +387,16 @@ void MCAsmLayout::LayoutFragment(MCFragment *F) { LastValidFragment[F->getParent()] = F; } -/// WriteFragmentData - Write the \p F data to the output file. -static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout, - const MCFragment &F) { +/// \brief Write the contents of a fragment to the given object writer. Expects +/// a MCEncodedFragment. +static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) { + MCEncodedFragment &EF = cast(F); + OW->WriteBytes(EF.getContents().str()); +} + +/// \brief Write the fragment \p F to the output file. +static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, + const MCFragment &F) { MCObjectWriter *OW = &Asm.getWriter(); uint64_t Start = OW->getStream().tell(); (void) Start; @@ -433,13 +445,15 @@ static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout, break; } - case MCFragment::FT_Data: { + case MCFragment::FT_Data: ++stats::EmittedDataFragments; - MCDataFragment &DF = cast(F); - assert(FragmentSize == DF.getContents().size() && "Invalid size!"); - OW->WriteBytes(DF.getContents().str()); + writeFragmentContents(F, OW); + break; + + case MCFragment::FT_Inst: + ++stats::EmittedInstFragments; + writeFragmentContents(F, OW); break; - } case MCFragment::FT_Fill: { MCFillFragment &FF = cast(F); @@ -458,13 +472,6 @@ static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout, break; } - case MCFragment::FT_Inst: { - ++stats::EmittedInstFragments; - MCInstFragment &IF = cast(F); - OW->WriteBytes(StringRef(IF.getCode().begin(), IF.getCode().size())); - break; - } - case MCFragment::FT_LEB: { MCLEBFragment &LF = cast(F); OW->WriteBytes(LF.getContents().str()); @@ -538,9 +545,9 @@ void MCAssembler::writeSectionData(const MCSectionData *SD, uint64_t Start = getWriter().getStream().tell(); (void)Start; - for (MCSectionData::const_iterator it = SD->begin(), - ie = SD->end(); it != ie; ++it) - WriteFragmentData(*this, Layout, *it); + for (MCSectionData::const_iterator it = SD->begin(), ie = SD->end(); + it != ie; ++it) + writeFragment(*this, Layout, *it); assert(getWriter().getStream().tell() - Start == Layout.getSectionAddressSize(SD)); @@ -617,24 +624,14 @@ void MCAssembler::Finish() { for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) { for (MCSectionData::iterator it2 = it->begin(), ie2 = it->end(); it2 != ie2; ++it2) { - MCDataFragment *DF = dyn_cast(it2); - if (DF) { - for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(), - ie3 = DF->fixup_end(); it3 != ie3; ++it3) { - MCFixup &Fixup = *it3; - uint64_t FixedValue = handleFixup(Layout, *DF, Fixup); - getBackend().applyFixup(Fixup, DF->getContents().data(), - DF->getContents().size(), FixedValue); - } - } - MCInstFragment *IF = dyn_cast(it2); - if (IF) { - for (MCInstFragment::fixup_iterator it3 = IF->fixup_begin(), - ie3 = IF->fixup_end(); it3 != ie3; ++it3) { + MCEncodedFragment *F = dyn_cast(it2); + if (F) { + for (MCEncodedFragment::fixup_iterator it3 = F->fixup_begin(), + ie3 = F->fixup_end(); it3 != ie3; ++it3) { MCFixup &Fixup = *it3; - uint64_t FixedValue = handleFixup(Layout, *IF, Fixup); - getBackend().applyFixup(Fixup, IF->getCode().data(), - IF->getCode().size(), FixedValue); + uint64_t FixedValue = handleFixup(Layout, *F, Fixup); + getBackend().applyFixup(Fixup, F->getContents().data(), + F->getContents().size(), FixedValue); } } } @@ -704,11 +701,8 @@ bool MCAssembler::relaxInstruction(MCAsmLayout &Layout, // Update the instruction fragment. IF.setInst(Relaxed); - IF.getCode() = Code; - IF.getFixups().clear(); - // FIXME: Eliminate copy. - for (unsigned i = 0, e = Fixups.size(); i != e; ++i) - IF.getFixups().push_back(Fixups[i]); + IF.getContents() = Code; + IF.getFixups() = Fixups; return true; } @@ -977,6 +971,7 @@ void MCAssembler::dump() { #endif // anchors for MC*Fragment vtables +void MCEncodedFragment::anchor() { } void MCDataFragment::anchor() { } void MCInstFragment::anchor() { } void MCAlignFragment::anchor() { } -- cgit v1.1 From 550f0ade457c3b042fa099ecff2c022c7ab58b1e Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Fri, 7 Dec 2012 22:06:56 +0000 Subject: Make the contents of encoded sections SmallVector instead of SmallString. This makes it possible to use the length-erased SmallVectorImpl in the interface without imposing buffer size. Thus, the size of MCInstFragment is back down since a preallocated 8-byte contents buffer is enough. It would be generally a good idea to rid all the fragments of SmallString as contents, because a vector just makes more sense. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169644 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index b2136e5..989d8be 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -391,7 +391,7 @@ void MCAsmLayout::LayoutFragment(MCFragment *F) { /// a MCEncodedFragment. static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) { MCEncodedFragment &EF = cast(F); - OW->WriteBytes(EF.getContents().str()); + OW->WriteBytes(EF.getContents()); } /// \brief Write the fragment \p F to the output file. -- cgit v1.1 From 6ac81f59a7954bd883bb194552eef1d91d04ad17 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Mon, 10 Dec 2012 18:59:39 +0000 Subject: This patch adds statistics for other non-DWARF fragments emitted by the assembler. This is useful in order to know how the numbers add up, since in particular the Align fragments account for a non-trivial portion of the emitted fragments (especially on -O0 which sets relax-all). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169747 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 989d8be..e8aa924 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -34,8 +34,16 @@ using namespace llvm; namespace { namespace stats { STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total"); -STATISTIC(EmittedInstFragments, "Number of emitted assembler fragments - instruction"); -STATISTIC(EmittedDataFragments, "Number of emitted assembler fragments - data"); +STATISTIC(EmittedInstFragments, + "Number of emitted assembler fragments - instruction"); +STATISTIC(EmittedDataFragments, + "Number of emitted assembler fragments - data"); +STATISTIC(EmittedAlignFragments, + "Number of emitted assembler fragments - align"); +STATISTIC(EmittedFillFragments, + "Number of emitted assembler fragments - fill"); +STATISTIC(EmittedOrgFragments, + "Number of emitted assembler fragments - org"); STATISTIC(evaluateFixup, "Number of evaluated fixups"); STATISTIC(FragmentLayouts, "Number of fragment layouts"); STATISTIC(ObjectBytes, "Number of emitted object file bytes"); @@ -407,6 +415,7 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F); switch (F.getKind()) { case MCFragment::FT_Align: { + ++stats::EmittedAlignFragments; MCAlignFragment &AF = cast(F); uint64_t Count = FragmentSize / AF.getValueSize(); @@ -456,6 +465,7 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, break; case MCFragment::FT_Fill: { + ++stats::EmittedFillFragments; MCFillFragment &FF = cast(F); assert(FF.getValueSize() && "Invalid virtual align in concrete fragment!"); @@ -479,6 +489,7 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, } case MCFragment::FT_Org: { + ++stats::EmittedOrgFragments; MCOrgFragment &OF = cast(F); for (uint64_t i = 0, e = FragmentSize; i != e; ++i) -- cgit v1.1 From f43e3fdb4ffddff6f71b5597c813c43e1e206564 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Mon, 10 Dec 2012 20:13:43 +0000 Subject: Cleanup formatting, comments and naming. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169762 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index e8aa924..8f8ec15 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -80,7 +80,7 @@ bool MCAsmLayout::isFragmentUpToDate(const MCFragment *F) const { return F->getLayoutOrder() <= LastValid->getLayoutOrder(); } -void MCAsmLayout::Invalidate(MCFragment *F) { +void MCAsmLayout::invalidateFragmentsAfter(MCFragment *F) { // If this fragment wasn't already up-to-date, we don't need to do anything. if (!isFragmentUpToDate(F)) return; @@ -678,7 +678,7 @@ bool MCAssembler::fragmentNeedsRelaxation(const MCInstFragment *IF, return false; for (MCInstFragment::const_fixup_iterator it = IF->fixup_begin(), - ie = IF->fixup_end(); it != ie; ++it) + ie = IF->fixup_end(); it != ie; ++it) if (fixupNeedsRelaxation(*it, IF, Layout)) return true; @@ -767,39 +767,39 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout, return OldSize != Data.size(); } -bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, - MCSectionData &SD) { +bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) { + // Holds the first fragment which needed relaxing during this layout. It will + // remain NULL if none were relaxed. MCFragment *FirstInvalidFragment = NULL; + // Scan for fragments that need relaxation. - for (MCSectionData::iterator it2 = SD.begin(), - ie2 = SD.end(); it2 != ie2; ++it2) { - // Check if this is an fragment that needs relaxation. - bool relaxedFrag = false; - switch(it2->getKind()) { + for (MCSectionData::iterator I = SD.begin(), IE = SD.end(); I != IE; ++I) { + // Check if this is a fragment that needs relaxation. + bool RelaxedFrag = false; + switch(I->getKind()) { default: - break; + break; case MCFragment::FT_Inst: - relaxedFrag = relaxInstruction(Layout, *cast(it2)); + RelaxedFrag = relaxInstruction(Layout, *cast(I)); break; case MCFragment::FT_Dwarf: - relaxedFrag = relaxDwarfLineAddr(Layout, - *cast(it2)); + RelaxedFrag = relaxDwarfLineAddr(Layout, + *cast(I)); break; case MCFragment::FT_DwarfFrame: - relaxedFrag = + RelaxedFrag = relaxDwarfCallFrameFragment(Layout, - *cast(it2)); + *cast(I)); break; case MCFragment::FT_LEB: - relaxedFrag = relaxLEB(Layout, *cast(it2)); + RelaxedFrag = relaxLEB(Layout, *cast(I)); break; } - // Update the layout, and remember that we relaxed. - if (relaxedFrag && !FirstInvalidFragment) - FirstInvalidFragment = it2; + if (RelaxedFrag && !FirstInvalidFragment) + FirstInvalidFragment = I; } if (FirstInvalidFragment) { - Layout.Invalidate(FirstInvalidFragment); + Layout.invalidateFragmentsAfter(FirstInvalidFragment); return true; } return false; @@ -811,7 +811,7 @@ bool MCAssembler::layoutOnce(MCAsmLayout &Layout) { bool WasRelaxed = false; for (iterator it = begin(), ie = end(); it != ie; ++it) { MCSectionData &SD = *it; - while(layoutSectionOnce(Layout, SD)) + while (layoutSectionOnce(Layout, SD)) WasRelaxed = true; } -- cgit v1.1 From 37a9830d20018dee5557a3a72f750d965ba383c5 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Tue, 11 Dec 2012 17:16:00 +0000 Subject: Remove the RelaxAll overrule in MCAssembler::fixupNeedsRelaxation, because that method is only getting called for MCInstFragment. These fragments aren't even generated when RelaxAll is set, which is why the flag reference here is superfluous. Removing it simplifies the code with no harmful effects. An assertion is added higher up to make sure this path is never reached. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169886 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 8f8ec15..9835e34 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -657,9 +657,6 @@ void MCAssembler::Finish() { bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup, const MCInstFragment *DF, const MCAsmLayout &Layout) const { - if (getRelaxAll()) - return true; - // If we cannot resolve the fixup value, it requires relaxation. MCValue Target; uint64_t Value; @@ -780,6 +777,8 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) { default: break; case MCFragment::FT_Inst: + assert(!getRelaxAll() && + "Did not expect a MCInstFragment in RelaxAll mode"); RelaxedFrag = relaxInstruction(Layout, *cast(I)); break; case MCFragment::FT_Dwarf: -- cgit v1.1 From d52a2c0a31a49e1a8fa16f6b975d01b1e934a49f Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 12 Dec 2012 19:54:05 +0000 Subject: Make naming consistent, add comments and sanity asserts git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170007 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 51 ++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 9835e34..c47299c 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -71,7 +71,7 @@ MCAsmLayout::MCAsmLayout(MCAssembler &Asm) SectionOrder.push_back(&*it); } -bool MCAsmLayout::isFragmentUpToDate(const MCFragment *F) const { +bool MCAsmLayout::isFragmentValid(const MCFragment *F) const { const MCSectionData &SD = *F->getParent(); const MCFragment *LastValid = LastValidFragment.lookup(&SD); if (!LastValid) @@ -81,8 +81,8 @@ bool MCAsmLayout::isFragmentUpToDate(const MCFragment *F) const { } void MCAsmLayout::invalidateFragmentsAfter(MCFragment *F) { - // If this fragment wasn't already up-to-date, we don't need to do anything. - if (!isFragmentUpToDate(F)) + // If this fragment wasn't already valid, we don't need to do anything. + if (!isFragmentValid(F)) return; // Otherwise, reset the last valid fragment to this fragment. @@ -90,7 +90,7 @@ void MCAsmLayout::invalidateFragmentsAfter(MCFragment *F) { LastValidFragment[&SD] = F; } -void MCAsmLayout::EnsureValid(const MCFragment *F) const { +void MCAsmLayout::ensureValid(const MCFragment *F) const { MCSectionData &SD = *F->getParent(); MCFragment *Cur = LastValidFragment[&SD]; @@ -99,15 +99,16 @@ void MCAsmLayout::EnsureValid(const MCFragment *F) const { else Cur = Cur->getNextNode(); - // Advance the layout position until the fragment is up-to-date. - while (!isFragmentUpToDate(F)) { - const_cast(this)->LayoutFragment(Cur); + // Advance the layout position until the fragment is valid. + while (!isFragmentValid(F)) { + assert(Cur && "Layout bookkeeping error"); + const_cast(this)->layoutFragment(Cur); Cur = Cur->getNextNode(); } } uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const { - EnsureValid(F); + ensureValid(F); assert(F->Offset != ~UINT64_C(0) && "Address not set!"); return F->Offset; } @@ -374,15 +375,15 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, llvm_unreachable("invalid fragment kind"); } -void MCAsmLayout::LayoutFragment(MCFragment *F) { +void MCAsmLayout::layoutFragment(MCFragment *F) { MCFragment *Prev = F->getPrevNode(); - // We should never try to recompute something which is up-to-date. - assert(!isFragmentUpToDate(F) && "Attempt to recompute up-to-date fragment!"); - // We should never try to compute the fragment layout if it's predecessor - // isn't up-to-date. - assert((!Prev || isFragmentUpToDate(Prev)) && - "Attempt to compute fragment before it's predecessor!"); + // We should never try to recompute something which is valid. + assert(!isFragmentValid(F) && "Attempt to recompute a valid fragment!"); + // We should never try to compute the fragment layout if its predecessor + // isn't valid. + assert((!Prev || isFragmentValid(Prev)) && + "Attempt to compute fragment before its predecessor!"); ++stats::FragmentLayouts; @@ -605,9 +606,9 @@ void MCAssembler::Finish() { SD->setLayoutOrder(i); unsigned FragmentIndex = 0; - for (MCSectionData::iterator it2 = SD->begin(), - ie2 = SD->end(); it2 != ie2; ++it2) - it2->setLayoutOrder(FragmentIndex++); + for (MCSectionData::iterator iFrag = SD->begin(), iFragEnd = SD->end(); + iFrag != iFragEnd; ++iFrag) + iFrag->setLayoutOrder(FragmentIndex++); } // Layout until everything fits. @@ -767,9 +768,11 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout, bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) { // Holds the first fragment which needed relaxing during this layout. It will // remain NULL if none were relaxed. - MCFragment *FirstInvalidFragment = NULL; + // When a fragment is relaxed, all the fragments following it should get + // invalidated because their offset is going to change. + MCFragment *FirstRelaxedFragment = NULL; - // Scan for fragments that need relaxation. + // Attempt to relax all the fragments in the section. for (MCSectionData::iterator I = SD.begin(), IE = SD.end(); I != IE; ++I) { // Check if this is a fragment that needs relaxation. bool RelaxedFrag = false; @@ -794,11 +797,11 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) { RelaxedFrag = relaxLEB(Layout, *cast(I)); break; } - if (RelaxedFrag && !FirstInvalidFragment) - FirstInvalidFragment = I; + if (RelaxedFrag && !FirstRelaxedFragment) + FirstRelaxedFragment = I; } - if (FirstInvalidFragment) { - Layout.invalidateFragmentsAfter(FirstInvalidFragment); + if (FirstRelaxedFragment) { + Layout.invalidateFragmentsAfter(FirstRelaxedFragment); return true; } return false; -- cgit v1.1 From 5399d2502acaf96fe8420e61913e77f0b23650ff Mon Sep 17 00:00:00 2001 From: Pedro Artigas Date: Wed, 12 Dec 2012 22:59:46 +0000 Subject: Make the MCStreamer have a reset method and call that after finalization of the asm printer, also changed MCContext to a single reset only method for simplicity as requested on the list git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170041 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index c47299c..8ca849b 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -221,6 +221,19 @@ MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_, MCAssembler::~MCAssembler() { } +void MCAssembler::reset() { + Sections.clear(); + Symbols.clear(); + SectionMap.clear(); + SymbolMap.clear(); + IndirectSymbols.clear(); + DataRegions.clear(); + ThumbFuncs.clear(); + RelaxAll = false; + NoExecStack = false; + SubsectionsViaSymbols = false; +} + bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const { // Non-temporary labels should always be visible to the linker. if (!Symbol.isTemporary()) -- cgit v1.1 From 99cbdde6198623ff014c776743caec2cf48f4840 Mon Sep 17 00:00:00 2001 From: Pedro Artigas Date: Fri, 14 Dec 2012 18:52:11 +0000 Subject: Add more reset methods to make all objects that the backend may use for outputting code have a reset, some are not used but were declared for completeness git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170227 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 8ca849b..2558eff 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -232,6 +232,11 @@ void MCAssembler::reset() { RelaxAll = false; NoExecStack = false; SubsectionsViaSymbols = false; + + // reset objects owned by us + getBackend().reset(); + getEmitter().reset(); + getWriter().reset(); } bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const { -- cgit v1.1 From 4766ef41b31e4f97bce1179c3b0398303bf65356 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Thu, 20 Dec 2012 19:05:53 +0000 Subject: Aligned bundling support. Following the discussion here: http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056754.html The proposal and implementation are fully documented here: https://sites.google.com/a/chromium.org/dev/nativeclient/pnacl/aligned-bundling-support-in-llvm Tests will follow shortly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170718 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 7 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 2558eff..f4c3fc5 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -160,6 +160,22 @@ uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const { return getSectionAddressSize(SD); } +uint64_t MCAsmLayout::computeBundlePadding(const MCFragment *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; + + // If the fragment would cross a bundle boundary, add enough padding until + // the end of the current bundle. + if (OffsetInBundle + FSize > BundleSize) + return BundleSize - OffsetInBundle; + else + return 0; +} + /* *** */ MCFragment::MCFragment() : Kind(FragmentType(~0)) { @@ -188,6 +204,7 @@ MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A) : Section(&_Section), Ordinal(~UINT32_C(0)), Alignment(1), + BundleLocked(false), BundleGroupBeforeFirstInst(false), HasInstructions(false) { if (A) @@ -406,12 +423,42 @@ void MCAsmLayout::layoutFragment(MCFragment *F) { ++stats::FragmentLayouts; // Compute fragment offset and size. - uint64_t Offset = 0; if (Prev) - Offset += Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev); - - F->Offset = Offset; + F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev); + else + F->Offset = 0; LastValidFragment[F->getParent()] = F; + + // If bundling is enabled and this fragment has instructions in it, it has to + // obey the bundling restrictions. With padding, we'll have: + // + // + // BundlePadding + // ||| + // ------------------------------------- + // Prev |##########| F | + // ------------------------------------- + // ^ + // | + // F->Offset + // + // The fragment's offset will point to after the padding, and its computed + // size won't include the padding. + // + if (Assembler.isBundlingEnabled() && F->hasInstructions()) { + assert(isa(F) && + "Only MCEncodedFragment implementations have instructions"); + uint64_t FSize = Assembler.computeFragmentSize(*this, *F); + + if (FSize > Assembler.getBundleAlignSize()) + report_fatal_error("Fragment can't be larger than a bundle size"); + + uint64_t RequiredBundlePadding = computeBundlePadding(F, F->Offset, FSize); + if (RequiredBundlePadding > UINT8_MAX) + report_fatal_error("Padding cannot exceed 255 bytes"); + F->setBundlePadding(static_cast(RequiredBundlePadding)); + F->Offset += RequiredBundlePadding; + } } /// \brief Write the contents of a fragment to the given object writer. Expects @@ -425,6 +472,22 @@ static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) { static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment &F) { MCObjectWriter *OW = &Asm.getWriter(); + + // Should NOP padding be written out before this fragment? + unsigned BundlePadding = F.getBundlePadding(); + if (BundlePadding > 0) { + assert(Asm.isBundlingEnabled() && + "Writing bundle padding with disabled bundling"); + assert(F.hasInstructions() && + "Writing bundle padding for a fragment without instructions"); + + if (!Asm.getBackend().writeNopData(BundlePadding, OW)) + report_fatal_error("unable to write NOP sequence of " + + Twine(BundlePadding) + " bytes"); + } + + // This variable (and its dummy usage) is to participate in the assert at + // the end of the function. uint64_t Start = OW->getStream().tell(); (void) Start; @@ -529,7 +592,8 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, } } - assert(OW->getStream().tell() - Start == FragmentSize); + assert(OW->getStream().tell() - Start == FragmentSize && + "The stream should advance by fragment size"); } void MCAssembler::writeSectionData(const MCSectionData *SD, @@ -875,7 +939,9 @@ void MCFragment::dump() { } OS << ""; + << " Offset:" << Offset + << " HasInstructions:" << hasInstructions() + << " BundlePadding:" << getBundlePadding() << ">"; switch (getKind()) { case MCFragment::FT_Align: { @@ -957,7 +1023,8 @@ void MCSectionData::dump() { raw_ostream &OS = llvm::errs(); OS << "dump(); -- cgit v1.1 From bc87361d25fc6f09745ded50d3cb0b811e1eba1c Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Thu, 20 Dec 2012 22:51:52 +0000 Subject: Fix an unitialized member variable that may have caused sporadic failures for code that wasn't even in bundling mode. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170793 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index f4c3fc5..20b64e2 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -232,7 +232,8 @@ MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_, MCCodeEmitter &Emitter_, MCObjectWriter &Writer_, raw_ostream &OS_) : Context(Context_), Backend(Backend_), Emitter(Emitter_), Writer(Writer_), - OS(OS_), RelaxAll(false), NoExecStack(false), SubsectionsViaSymbols(false) { + OS(OS_), BundleAlignSize(0), RelaxAll(false), NoExecStack(false), + SubsectionsViaSymbols(false) { } MCAssembler::~MCAssembler() { -- cgit v1.1 From 6c1d4972cf1cd6b6072e31c05f97abb1ed7a8497 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Mon, 7 Jan 2013 21:51:08 +0000 Subject: Add the align_to_end option to .bundle_lock in the MC implementation of aligned bundling. The document describing this feature and the implementation has also been updated: https://sites.google.com/a/chromium.org/dev/nativeclient/pnacl/aligned-bundling-support-in-llvm git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171797 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 20b64e2..d30dc7d 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -167,10 +167,34 @@ uint64_t MCAsmLayout::computeBundlePadding(const MCFragment *F, "computeBundlePadding should only be called if bundling is enabled"); uint64_t BundleMask = BundleSize - 1; uint64_t OffsetInBundle = FOffset & BundleMask; - - // If the fragment would cross a bundle boundary, add enough padding until - // the end of the current bundle. - if (OffsetInBundle + FSize > BundleSize) + 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 (EndOfFragment > BundleSize) return BundleSize - OffsetInBundle; else return 0; @@ -204,7 +228,7 @@ MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A) : Section(&_Section), Ordinal(~UINT32_C(0)), Alignment(1), - BundleLocked(false), BundleGroupBeforeFirstInst(false), + BundleLockState(NotBundleLocked), BundleGroupBeforeFirstInst(false), HasInstructions(false) { if (A) -- cgit v1.1 From 251040bc18eedfa56d01fe92836e55cfd8c5d990 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Tue, 8 Jan 2013 00:22:56 +0000 Subject: Renamed MCInstFragment to MCRelaxableFragment and added some comments. No change in functionality. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171822 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index d30dc7d..b361536 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -390,8 +390,8 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, return cast(F).getContents().size(); case MCFragment::FT_Fill: return cast(F).getSize(); - case MCFragment::FT_Inst: - return cast(F).getInstSize(); + case MCFragment::FT_Relaxable: + return cast(F).getInstSize(); case MCFragment::FT_LEB: return cast(F).getContents().size(); @@ -566,7 +566,7 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, writeFragmentContents(F, OW); break; - case MCFragment::FT_Inst: + case MCFragment::FT_Relaxable: ++stats::EmittedInstFragments; writeFragmentContents(F, OW); break; @@ -763,7 +763,7 @@ void MCAssembler::Finish() { } bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup, - const MCInstFragment *DF, + const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const { // If we cannot resolve the fixup value, it requires relaxation. MCValue Target; @@ -774,25 +774,25 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup, return getBackend().fixupNeedsRelaxation(Fixup, Value, DF, Layout); } -bool MCAssembler::fragmentNeedsRelaxation(const MCInstFragment *IF, +bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F, const MCAsmLayout &Layout) const { // If this inst doesn't ever need relaxation, ignore it. This occurs when we // are intentionally pushing out inst fragments, or because we relaxed a // previous instruction to one that doesn't need relaxation. - if (!getBackend().mayNeedRelaxation(IF->getInst())) + if (!getBackend().mayNeedRelaxation(F->getInst())) return false; - for (MCInstFragment::const_fixup_iterator it = IF->fixup_begin(), - ie = IF->fixup_end(); it != ie; ++it) - if (fixupNeedsRelaxation(*it, IF, Layout)) + for (MCRelaxableFragment::const_fixup_iterator it = F->fixup_begin(), + ie = F->fixup_end(); it != ie; ++it) + if (fixupNeedsRelaxation(*it, F, Layout)) return true; return false; } bool MCAssembler::relaxInstruction(MCAsmLayout &Layout, - MCInstFragment &IF) { - if (!fragmentNeedsRelaxation(&IF, Layout)) + MCRelaxableFragment &F) { + if (!fragmentNeedsRelaxation(&F, Layout)) return false; ++stats::RelaxedInstructions; @@ -803,7 +803,7 @@ bool MCAssembler::relaxInstruction(MCAsmLayout &Layout, // Relax the fragment. MCInst Relaxed; - getBackend().relaxInstruction(IF.getInst(), Relaxed); + getBackend().relaxInstruction(F.getInst(), Relaxed); // Encode the new instruction. // @@ -815,10 +815,10 @@ bool MCAssembler::relaxInstruction(MCAsmLayout &Layout, getEmitter().EncodeInstruction(Relaxed, VecOS, Fixups); VecOS.flush(); - // Update the instruction fragment. - IF.setInst(Relaxed); - IF.getContents() = Code; - IF.getFixups() = Fixups; + // Update the fragment. + F.setInst(Relaxed); + F.getContents() = Code; + F.getFixups() = Fixups; return true; } @@ -886,10 +886,10 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) { switch(I->getKind()) { default: break; - case MCFragment::FT_Inst: + case MCFragment::FT_Relaxable: assert(!getRelaxAll() && - "Did not expect a MCInstFragment in RelaxAll mode"); - RelaxedFrag = relaxInstruction(Layout, *cast(I)); + "Did not expect a MCRelaxableFragment in RelaxAll mode"); + RelaxedFrag = relaxInstruction(Layout, *cast(I)); break; case MCFragment::FT_Dwarf: RelaxedFrag = relaxDwarfLineAddr(Layout, @@ -956,7 +956,7 @@ void MCFragment::dump() { case MCFragment::FT_Align: OS << "MCAlignFragment"; break; case MCFragment::FT_Data: OS << "MCDataFragment"; break; case MCFragment::FT_Fill: OS << "MCFillFragment"; break; - case MCFragment::FT_Inst: OS << "MCInstFragment"; break; + case MCFragment::FT_Relaxable: OS << "MCRelaxableFragment"; break; case MCFragment::FT_Org: OS << "MCOrgFragment"; break; case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break; case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break; @@ -1008,11 +1008,11 @@ void MCFragment::dump() { << " Size:" << FF->getSize(); break; } - case MCFragment::FT_Inst: { - const MCInstFragment *IF = cast(this); + case MCFragment::FT_Relaxable: { + const MCRelaxableFragment *F = cast(this); OS << "\n "; OS << " Inst:"; - IF->getInst().dump_pretty(OS); + F->getInst().dump_pretty(OS); break; } case MCFragment::FT_Org: { @@ -1096,7 +1096,7 @@ void MCAssembler::dump() { // anchors for MC*Fragment vtables void MCEncodedFragment::anchor() { } void MCDataFragment::anchor() { } -void MCInstFragment::anchor() { } +void MCRelaxableFragment::anchor() { } void MCAlignFragment::anchor() { } void MCFillFragment::anchor() { } void MCOrgFragment::anchor() { } -- cgit v1.1 From 6f6204f2351afcd11fb83125a06c539a40b43b95 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Tue, 8 Jan 2013 17:41:59 +0000 Subject: Rename statistic for instruction fragments -> relaxable git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171872 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index b361536..ee5ac1d 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -34,8 +34,8 @@ using namespace llvm; namespace { namespace stats { STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total"); -STATISTIC(EmittedInstFragments, - "Number of emitted assembler fragments - instruction"); +STATISTIC(EmittedRelaxableFragments, + "Number of emitted assembler fragments - relaxable"); STATISTIC(EmittedDataFragments, "Number of emitted assembler fragments - data"); STATISTIC(EmittedAlignFragments, @@ -567,7 +567,7 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout, break; case MCFragment::FT_Relaxable: - ++stats::EmittedInstFragments; + ++stats::EmittedRelaxableFragments; writeFragmentContents(F, OW); break; -- cgit v1.1 From 0fdcef6030fb69bee45f604c71c53bebb17c1079 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Tue, 8 Jan 2013 22:05:10 +0000 Subject: Simplify the code a bit: MCRelaxableFragment doesn't need a separate getInstSize method because getContents().size() already covers it. So computeFragmentSize can use the generic MCEncodedFragment interface when querying both Data and Relaxable fragments for contents sizes. No change in functionality git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171903 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAssembler.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/MC/MCAssembler.cpp') diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index ee5ac1d..5fdc57a 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -387,11 +387,10 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout, const MCFragment &F) const { switch (F.getKind()) { case MCFragment::FT_Data: - return cast(F).getContents().size(); + case MCFragment::FT_Relaxable: + return cast(F).getContents().size(); case MCFragment::FT_Fill: return cast(F).getSize(); - case MCFragment::FT_Relaxable: - return cast(F).getInstSize(); case MCFragment::FT_LEB: return cast(F).getContents().size(); -- cgit v1.1