[llvm-commits] [llvm] r103738 - in /llvm/trunk: include/llvm/MC/MCAsmLayout.h include/llvm/MC/MCAssembler.h lib/MC/MCAssembler.cpp

Daniel Dunbar daniel at zuster.org
Thu May 13 13:40:12 PDT 2010


Author: ddunbar
Date: Thu May 13 15:40:12 2010
New Revision: 103738

URL: http://llvm.org/viewvc/llvm-project?rev=103738&view=rev
Log:
MC: Move Layout{Fragment,Section} into MCAsmLayout, and add LayoutFile().

Modified:
    llvm/trunk/include/llvm/MC/MCAsmLayout.h
    llvm/trunk/include/llvm/MC/MCAssembler.h
    llvm/trunk/lib/MC/MCAssembler.cpp

Modified: llvm/trunk/include/llvm/MC/MCAsmLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLayout.h?rev=103738&r1=103737&r2=103738&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Thu May 13 15:40:12 2010
@@ -50,6 +50,18 @@
   /// \brief Update the layout because a fragment has been replaced.
   void FragmentReplaced(MCFragment *Src, MCFragment *Dst);
 
+  /// \brief Perform a full layout.
+  void LayoutFile();
+
+  /// \brief Perform layout for a single fragment, assuming that the previous
+  /// fragment has already been layed out correctly, and the parent section has
+  /// been initialized.
+  void LayoutFragment(MCFragment *Fragment);
+
+  /// \brief Performs layout for a single section, assuming that the previous
+  /// section has already been layed out correctly.
+  void LayoutSection(MCSectionData *SD);
+
   /// @name Section Access (in layout order)
   /// @{
 

Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=103738&r1=103737&r2=103738&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Thu May 13 15:40:12 2010
@@ -656,16 +656,6 @@
                                uint64_t SectionAddress,
                                uint64_t FragmentOffset) const;
 
-  /// LayoutFragment - Performs layout of the given \arg Fragment; assuming that
-  /// the previous fragment has already been layed out correctly, and the parent
-  /// section has been initialized.
-  void LayoutFragment(MCAsmLayout &Layout, MCFragment &Fragment);
-
-  /// LayoutSection - Performs layout of the section referenced by the given
-  /// \arg SectionOrderIndex. The layout assumes that the previous section has
-  /// already been layed out correctly.
-  void LayoutSection(MCAsmLayout &Layout, unsigned SectionOrderIndex);
-
   /// LayoutOnce - Perform one layout iteration and return true if any offsets
   /// were adjusted.
   bool LayoutOnce(MCAsmLayout &Layout);

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=103738&r1=103737&r2=103738&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Thu May 13 15:40:12 2010
@@ -69,8 +69,7 @@
   // FIXME-PERF: This is O(N^2), but will be eliminated once we get smarter.
 
   // Layout the sections in order.
-  for (unsigned i = 0, e = getSectionOrder().size(); i != e; ++i)
-    getAssembler().LayoutSection(*this, i);
+  LayoutFile();
 }
 
 void MCAsmLayout::FragmentReplaced(MCFragment *Src, MCFragment *Dst) {
@@ -426,49 +425,52 @@
   return 0;
 }
 
-void MCAssembler::LayoutFragment(MCAsmLayout &Layout, MCFragment &F) {
-  uint64_t StartAddress = Layout.getSectionAddress(F.getParent());
+void MCAsmLayout::LayoutFile() {
+  for (unsigned i = 0, e = getSectionOrder().size(); i != e; ++i)
+    LayoutSection(getSectionOrder()[i]);
+}
+
+void MCAsmLayout::LayoutFragment(MCFragment *F) {
+  uint64_t StartAddress = getSectionAddress(F->getParent());
 
   // Get the fragment start address.
   uint64_t Address = StartAddress;
-  MCSectionData::iterator it = &F;
-  if (MCFragment *Prev = F.getPrevNode())
-    Address = (StartAddress + Layout.getFragmentOffset(Prev) +
-               Layout.getFragmentEffectiveSize(Prev));
+  MCSectionData::iterator it = F;
+  if (MCFragment *Prev = F->getPrevNode())
+    Address = (StartAddress + getFragmentOffset(Prev) +
+               getFragmentEffectiveSize(Prev));
 
   ++stats::FragmentLayouts;
 
-  uint64_t FragmentOffset = Address - StartAddress;
-  Layout.setFragmentOffset(&F, FragmentOffset);
+  // Compute fragment offset and size.
+  uint64_t Offset = Address - StartAddress;
+  uint64_t EffectiveSize =
+    getAssembler().ComputeFragmentSize(*this, *F, StartAddress, Offset);
 
-  // Evaluate fragment size.
-  uint64_t EffectiveSize = ComputeFragmentSize(Layout, F, StartAddress,
-                                               FragmentOffset);
-  Layout.setFragmentEffectiveSize(&F, EffectiveSize);
+  setFragmentOffset(F, Offset);
+  setFragmentEffectiveSize(F, EffectiveSize);
 }
 
-void MCAssembler::LayoutSection(MCAsmLayout &Layout,
-                                unsigned SectionOrderIndex) {
-  MCSectionData &SD = *Layout.getSectionOrder()[SectionOrderIndex];
+void MCAsmLayout::LayoutSection(MCSectionData *SD) {
+  unsigned SectionOrderIndex = SD->getLayoutOrder();
 
   ++stats::SectionLayouts;
 
   // Compute the section start address.
   uint64_t StartAddress = 0;
   if (SectionOrderIndex) {
-    MCSectionData *Prev = Layout.getSectionOrder()[SectionOrderIndex - 1];
-    StartAddress = (Layout.getSectionAddress(Prev) +
-                    Layout.getSectionAddressSize(Prev));
+    MCSectionData *Prev = getSectionOrder()[SectionOrderIndex - 1];
+    StartAddress = getSectionAddress(Prev) + getSectionAddressSize(Prev);
   }
 
   // Honor the section alignment requirements.
-  StartAddress = RoundUpToAlignment(StartAddress, SD.getAlignment());
+  StartAddress = RoundUpToAlignment(StartAddress, SD->getAlignment());
 
   // Set the section address.
-  Layout.setSectionAddress(&SD, StartAddress);
+  setSectionAddress(SD, StartAddress);
 
-  for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it)
-    LayoutFragment(Layout, *it);
+  for (MCSectionData::iterator it = SD->begin(), ie = SD->end(); it != ie; ++it)
+    LayoutFragment(it);
 }
 
 /// WriteFragmentData - Write the \arg F data to the output file.
@@ -754,8 +756,7 @@
   ++stats::RelaxationSteps;
 
   // Layout the sections in order.
-  for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i)
-    LayoutSection(Layout, i);
+  Layout.LayoutFile();
 
   // Scan for fragments that need relaxation.
   bool WasRelaxed = false;





More information about the llvm-commits mailing list