Layout one section until no relaxations are done and then move to the next
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 21 Dec 2010 04:22:09 +0000 (04:22 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 21 Dec 2010 04:22:09 +0000 (04:22 +0000)
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
lib/MC/MCAssembler.cpp

index 0c37189bd8fb1341ab77f4d926c1725bdd8d3f1e..7d8bae9f37ee89427aaa287027641ecaeea9345e 100644 (file)
@@ -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);
index 2d89fb3ed9965984f3997f7f7191045b9f01b4b9..ed4401d749f155d9c82ae44c30032e57cce5fce4 100644 (file)
@@ -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<MCAlignFragment>(it2));
+      break;
+    case MCFragment::FT_Inst:
+      relaxedFrag = RelaxInstruction(Layout, *cast<MCInstFragment>(it2));
+      break;
+    case MCFragment::FT_Org:
+      relaxedFrag = RelaxOrg(Layout, *cast<MCOrgFragment>(it2));
+      break;
+    case MCFragment::FT_Dwarf:
+      relaxedFrag = RelaxDwarfLineAddr(Layout,
+                                       *cast<MCDwarfLineAddrFragment>(it2));
+      break;
+        case MCFragment::FT_LEB:
+          relaxedFrag = RelaxLEB(Layout, *cast<MCLEBFragment>(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<MCAlignFragment>(it2));
-       break;
-      case MCFragment::FT_Inst:
-        relaxedFrag = RelaxInstruction(Layout, *cast<MCInstFragment>(it2));
-        break;
-      case MCFragment::FT_Org:
-        relaxedFrag = RelaxOrg(Layout, *cast<MCOrgFragment>(it2));
-        break;
-      case MCFragment::FT_Dwarf:
-        relaxedFrag = RelaxDwarfLineAddr(Layout,
-                                         *cast<MCDwarfLineAddrFragment>(it2));
-       break;
-      case MCFragment::FT_LEB:
-        relaxedFrag = RelaxLEB(Layout, *cast<MCLEBFragment>(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;