diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-12-20 22:31:43 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-12-20 22:31:43 +0000 |
commit | 41d2daa9344a4c4e8bb88dba51cd087c0648b695 (patch) | |
tree | 7e22b30849a5a15a044a3423d0e8df884992ceea /lib/MC/MCAssembler.cpp | |
parent | 571f3e0cc9e767d1e3dcfd3e7e0b3d11ec4f7884 (diff) | |
parent | 6c583141bf6b7a6b5f8125c1037ecbc089813288 (diff) |
Updating branches/google/testing to 170392
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/google/testing@170779 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCAssembler.cpp')
-rw-r--r-- | lib/MC/MCAssembler.cpp | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 8f8ec151e5..2558eff045 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<MCAsmLayout*>(this)->LayoutFragment(Cur); + // Advance the layout position until the fragment is valid. + while (!isFragmentValid(F)) { + assert(Cur && "Layout bookkeeping error"); + const_cast<MCAsmLayout*>(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; } @@ -220,6 +221,24 @@ 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; + + // reset objects owned by us + getBackend().reset(); + getEmitter().reset(); + getWriter().reset(); +} + bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const { // Non-temporary labels should always be visible to the linker. if (!Symbol.isTemporary()) @@ -374,15 +393,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 +624,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. @@ -657,9 +676,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; @@ -770,9 +786,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; @@ -780,6 +798,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<MCInstFragment>(I)); break; case MCFragment::FT_Dwarf: @@ -795,11 +815,11 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) { RelaxedFrag = relaxLEB(Layout, *cast<MCLEBFragment>(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; |