[llvm-commits] [llvm] r118377 - /llvm/trunk/lib/MC/MCAssembler.cpp

Rafael Espindola rafael.espindola at gmail.com
Sun Nov 7 07:03:28 PST 2010


Author: rafael
Date: Sun Nov  7 09:03:27 2010
New Revision: 118377

URL: http://llvm.org/viewvc/llvm-project?rev=118377&view=rev
Log:
Speed up AddSectionToTheEnd. It was walking all fragments in all sections.
This is really slow with we have 1000s of sections each with a corresponding
relocation section. Also, it is only used by the ELF writer to add
basic data, so there is no need to force a new layout pass.

Should fix PR8563.

Modified:
    llvm/trunk/lib/MC/MCAssembler.cpp

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=118377&r1=118376&r2=118377&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Sun Nov  7 09:03:27 2010
@@ -590,24 +590,14 @@
 void MCAssembler::AddSectionToTheEnd(const MCObjectWriter &Writer,
                                      MCSectionData &SD, MCAsmLayout &Layout) {
   // Create dummy fragments and assign section ordinals.
-  unsigned SectionIndex = 0;
-  for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it)
-    SectionIndex++;
-
+  unsigned SectionIndex = size();
   SD.setOrdinal(SectionIndex);
 
   // Assign layout order indices to sections and fragments.
-  unsigned FragmentIndex = 0;
-  unsigned i = 0;
-  for (unsigned e = Layout.getSectionOrder().size(); i != e; ++i) {
-    MCSectionData *SD = Layout.getSectionOrder()[i];
-
-    for (MCSectionData::iterator it2 = SD->begin(),
-           ie2 = SD->end(); it2 != ie2; ++it2)
-      FragmentIndex++;
-  }
+  const MCFragment &Last = *Layout.getSectionOrder().back()->rbegin();
+  unsigned FragmentIndex = Last.getLayoutOrder() + 1;
 
-  SD.setLayoutOrder(i);
+  SD.setLayoutOrder(Layout.getSectionOrder().size());
   for (MCSectionData::iterator it2 = SD.begin(),
          ie2 = SD.end(); it2 != ie2; ++it2) {
     it2->setLayoutOrder(FragmentIndex++);
@@ -615,11 +605,6 @@
   Layout.getSectionOrder().push_back(&SD);
 
   Layout.LayoutSection(&SD);
-
-  // Layout until everything fits.
-  while (LayoutOnce(Writer, Layout))
-    continue;
-
 }
 
 void MCAssembler::Finish(MCObjectWriter *Writer) {





More information about the llvm-commits mailing list