From 62b83b62f377ac248038672015dc65970327f786 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 21 Dec 2010 04:22:09 +0000 Subject: [PATCH] Layout one section until no relaxations are done and then move to the next section. This helps because in practice sections form a dag with debug sections pointing to text sections. Finishing up the text sections first makes the debug section relaxation trivial. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122314 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 2 + lib/MC/MCAssembler.cpp | 75 +++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h index 0c37189bd8f..7d8bae9f37e 100644 --- a/include/llvm/MC/MCAssembler.h +++ b/include/llvm/MC/MCAssembler.h @@ -711,6 +711,8 @@ private: /// were adjusted. bool LayoutOnce(MCAsmLayout &Layout); + bool LayoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD); + bool RelaxInstruction(MCAsmLayout &Layout, MCInstFragment &IF); bool RelaxOrg(MCAsmLayout &Layout, MCOrgFragment &OF); diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 2d89fb3ed99..ed4401d749f 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -707,46 +707,53 @@ bool MCAssembler::RelaxAlignment(MCAsmLayout &Layout, return OldSize != Size; } +bool MCAssembler::LayoutSectionOnce(MCAsmLayout &Layout, + MCSectionData &SD) { + 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()) { + default: + break; + case MCFragment::FT_Align: + relaxedFrag = RelaxAlignment(Layout, *cast(it2)); + break; + case MCFragment::FT_Inst: + relaxedFrag = RelaxInstruction(Layout, *cast(it2)); + break; + case MCFragment::FT_Org: + relaxedFrag = RelaxOrg(Layout, *cast(it2)); + break; + case MCFragment::FT_Dwarf: + relaxedFrag = RelaxDwarfLineAddr(Layout, + *cast(it2)); + break; + case MCFragment::FT_LEB: + relaxedFrag = RelaxLEB(Layout, *cast(it2)); + break; + } + // Update the layout, and remember that we relaxed. + if (relaxedFrag && !FirstInvalidFragment) + FirstInvalidFragment = it2; + } + if (FirstInvalidFragment) { + Layout.Invalidate(FirstInvalidFragment); + return true; + } + return false; +} + bool MCAssembler::LayoutOnce(MCAsmLayout &Layout) { ++stats::RelaxationSteps; - // Scan for fragments that need relaxation. bool WasRelaxed = false; for (iterator it = begin(), ie = end(); it != ie; ++it) { MCSectionData &SD = *it; - MCFragment *FirstInvalidFragment = NULL; - - 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()) { - default: - break; - case MCFragment::FT_Align: - relaxedFrag = RelaxAlignment(Layout, *cast(it2)); - break; - case MCFragment::FT_Inst: - relaxedFrag = RelaxInstruction(Layout, *cast(it2)); - break; - case MCFragment::FT_Org: - relaxedFrag = RelaxOrg(Layout, *cast(it2)); - break; - case MCFragment::FT_Dwarf: - relaxedFrag = RelaxDwarfLineAddr(Layout, - *cast(it2)); - break; - case MCFragment::FT_LEB: - relaxedFrag = RelaxLEB(Layout, *cast(it2)); - break; - } - // Update the layout, and remember that we relaxed. - if (relaxedFrag && !FirstInvalidFragment) - FirstInvalidFragment = it2; - WasRelaxed |= relaxedFrag; - } - if (FirstInvalidFragment) - Layout.Invalidate(FirstInvalidFragment); + while(LayoutSectionOnce(Layout, SD)) + WasRelaxed = true; } return WasRelaxed; -- 2.34.1