MC: Simplify LayoutSection to just take the index of the section to layout.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103627 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2010-05-12 17:56:47 +00:00
parent 473a09d80a
commit d13a0caf72
3 changed files with 26 additions and 31 deletions

View File

@@ -50,11 +50,12 @@ public:
/// @name Section Access (in layout order) /// @name Section Access (in layout order)
/// @{ /// @{
iterator begin() { return SectionOrder.begin(); } llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() {
const_iterator begin() const { return SectionOrder.begin(); } return SectionOrder;
}
iterator end() {return SectionOrder.end();} const llvm::SmallVectorImpl<MCSectionData*> &getSectionOrder() const {
const_iterator end() const {return SectionOrder.end();} return SectionOrder;
}
/// @} /// @}
/// @name Fragment Layout Data /// @name Fragment Layout Data

View File

@@ -668,14 +668,10 @@ private:
bool FragmentNeedsRelaxation(const MCInstFragment *IF, bool FragmentNeedsRelaxation(const MCInstFragment *IF,
const MCAsmLayout &Layout) const; const MCAsmLayout &Layout) const;
/// LayoutSection - Assign the section the given \arg StartAddress, and then /// LayoutSection - Performs layout of the section referenced by the given
/// assign offsets and sizes to the fragments in the section \arg SD, and /// \arg SectionOrderIndex. The layout assumes that the previous section has
/// update the section size. /// already been layed out correctly.
/// void LayoutSection(MCAsmLayout &Layout, unsigned SectionOrderIndex);
/// \return The address at the end of the section, for use in laying out the
/// succeeding section.
uint64_t LayoutSection(MCSectionData &SD, MCAsmLayout &Layout,
uint64_t StartAddress);
/// LayoutOnce - Perform one layout iteration and return true if any offsets /// LayoutOnce - Perform one layout iteration and return true if any offsets
/// were adjusted. /// were adjusted.

View File

@@ -68,12 +68,9 @@ void MCAsmLayout::UpdateForSlide(MCFragment *F, int SlideAmount) {
// //
// FIXME-PERF: This is O(N^2), but will be eliminated once we get smarter. // FIXME-PERF: This is O(N^2), but will be eliminated once we get smarter.
// Layout the concrete sections and fragments. // Layout the sections in order.
uint64_t Address = 0; for (unsigned i = 0, e = getSectionOrder().size(); i != e; ++i)
for (iterator it = begin(), ie = end(); it != ie; ++it) { getAssembler().LayoutSection(*this, i);
// Layout the section fragments and its size.
Address = getAssembler().LayoutSection(**it, *this, Address);
}
} }
uint64_t MCAsmLayout::getFragmentAddress(const MCFragment *F) const { uint64_t MCAsmLayout::getFragmentAddress(const MCFragment *F) const {
@@ -365,13 +362,20 @@ bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout,
return IsResolved; return IsResolved;
} }
uint64_t MCAssembler::LayoutSection(MCSectionData &SD, void MCAssembler::LayoutSection(MCAsmLayout &Layout,
MCAsmLayout &Layout, unsigned SectionOrderIndex) {
uint64_t StartAddress) { MCSectionData &SD = *Layout.getSectionOrder()[SectionOrderIndex];
bool IsVirtual = getBackend().isVirtualSection(SD.getSection()); bool IsVirtual = getBackend().isVirtualSection(SD.getSection());
++stats::SectionLayouts; ++stats::SectionLayouts;
// Get the section start address.
uint64_t StartAddress = 0;
if (SectionOrderIndex) {
MCSectionData *Prev = Layout.getSectionOrder()[SectionOrderIndex - 1];
StartAddress = Layout.getSectionAddress(Prev) + Layout.getSectionSize(Prev);
}
// Align this section if necessary by adding padding bytes to the previous // Align this section if necessary by adding padding bytes to the previous
// section. It is safe to adjust this out-of-band, because no symbol or // section. It is safe to adjust this out-of-band, because no symbol or
// fragment is allowed to point past the end of the section at any time. // fragment is allowed to point past the end of the section at any time.
@@ -469,8 +473,6 @@ uint64_t MCAssembler::LayoutSection(MCSectionData &SD,
Layout.setSectionFileSize(&SD, 0); Layout.setSectionFileSize(&SD, 0);
else else
Layout.setSectionFileSize(&SD, Address - StartAddress); Layout.setSectionFileSize(&SD, Address - StartAddress);
return Address;
} }
/// WriteFragmentData - Write the \arg F data to the output file. /// WriteFragmentData - Write the \arg F data to the output file.
@@ -705,13 +707,9 @@ bool MCAssembler::FragmentNeedsRelaxation(const MCInstFragment *IF,
bool MCAssembler::LayoutOnce(MCAsmLayout &Layout) { bool MCAssembler::LayoutOnce(MCAsmLayout &Layout) {
++stats::RelaxationSteps; ++stats::RelaxationSteps;
// Layout the concrete sections and fragments. // Layout the sections in order.
uint64_t Address = 0; for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i)
for (MCAsmLayout::iterator it = Layout.begin(), LayoutSection(Layout, i);
ie = Layout.end(); it != ie; ++it) {
// Layout the section fragments and its size.
Address = LayoutSection(**it, Layout, Address);
}
// Scan for fragments that need relaxation. // Scan for fragments that need relaxation.
bool WasRelaxed = false; bool WasRelaxed = false;