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

Daniel Dunbar daniel at zuster.org
Wed May 12 20:19:50 PDT 2010


Author: ddunbar
Date: Wed May 12 22:19:50 2010
New Revision: 103695

URL: http://llvm.org/viewvc/llvm-project?rev=103695&view=rev
Log:
MC: Eliminate MCSectionData::{,Address,File}Size, which can now be computed by
utility functions.

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=103695&r1=103694&r2=103695&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Wed May 12 22:19:50 2010
@@ -84,35 +84,26 @@
   /// \brief Set the computed address of the given section.
   void setSectionAddress(MCSectionData *SD, uint64_t Value);
 
-  /// \brief Get the data size of the given section, as emitted to the object
-  /// file. This may include additional padding, or be 0 for virtual sections.
-  uint64_t getSectionFileSize(const MCSectionData *SD) const;
+  /// @}
+  /// @name Utility Functions
+  /// @{
 
-  /// \brief Set the data size of the given section.
-  void setSectionFileSize(MCSectionData *SD, uint64_t Value);
+  /// \brief Get the address of the given fragment, as computed in the current
+  /// layout.
+  uint64_t getFragmentAddress(const MCFragment *F) const;
 
   /// \brief Get the address space size of the given section, as it effects
   /// layout. This may differ from the size reported by \see getSectionSize() by
   /// not including section tail padding.
   uint64_t getSectionAddressSize(const MCSectionData *SD) const;
 
-  /// \brief Set the address space size of the given section.
-  void setSectionAddressSize(MCSectionData *SD, uint64_t Value);
+  /// \brief Get the data size of the given section, as emitted to the object
+  /// file. This may include additional padding, or be 0 for virtual sections.
+  uint64_t getSectionFileSize(const MCSectionData *SD) const;
 
   /// \brief Get the logical data size of the given section.
   uint64_t getSectionSize(const MCSectionData *SD) const;
 
-  /// \brief Set the logical data size of the given section.
-  void setSectionSize(MCSectionData *SD, uint64_t Value);
-
-  /// @}
-  /// @name Utility Functions
-  /// @{
-
-  /// \brief Get the address of the given fragment, as computed in the current
-  /// layout.
-  uint64_t getFragmentAddress(const MCFragment *F) const;
-
   /// \brief Get the address of the given symbol, as computed in the current
   /// layout.
   uint64_t getSymbolAddress(const MCSymbolData *SD) const;

Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=103695&r1=103694&r2=103695&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Wed May 12 22:19:50 2010
@@ -404,17 +404,6 @@
   /// initialized.
   uint64_t Address;
 
-  /// Size - The logical size of this section. This is ~0 until initialized.
-  uint64_t Size;
-
-  /// AddressSize - The address space size used by this section. This is ~0
-  /// until initialized.
-  uint64_t AddressSize;
-
-  /// FileSize - The size of this section in the object file. This is ~0 until
-  /// initialized.
-  uint64_t FileSize;
-
   /// HasInstructions - Whether this section has had instructions emitted into
   /// it.
   unsigned HasInstructions : 1;

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=103695&r1=103694&r2=103695&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Wed May 12 22:19:50 2010
@@ -110,28 +110,38 @@
   SD->Address = Value;
 }
 
-uint64_t MCAsmLayout::getSectionSize(const MCSectionData *SD) const {
-  assert(SD->Size != ~UINT64_C(0) && "File size not set!");
-  return SD->Size;
-}
-void MCAsmLayout::setSectionSize(MCSectionData *SD, uint64_t Value) {
-  SD->Size = Value;
+uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const {
+  // Empty sections have no size.
+  if (SD->getFragmentList().empty())
+    return 0;
+
+  // Otherwise, the size is the last fragment's end offset.
+  const MCFragment &F = SD->getFragmentList().back();
+  return getFragmentOffset(&F) + getFragmentEffectiveSize(&F);
 }
 
 uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const {
-  assert(SD->FileSize != ~UINT64_C(0) && "File size not set!");
-  return SD->FileSize;
-}
-void MCAsmLayout::setSectionFileSize(MCSectionData *SD, uint64_t Value) {
-  SD->FileSize = Value;
-}
+  // Virtual sections have no file size.
+  if (getAssembler().getBackend().isVirtualSection(SD->getSection()))
+    return 0;
 
-uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const {
-  assert(SD->AddressSize != ~UINT64_C(0) && "Address size not set!");
-  return SD->AddressSize;
+  // Otherwise, the file size is the same as the address space size.
+  return getSectionAddressSize(SD);
 }
-void MCAsmLayout::setSectionAddressSize(MCSectionData *SD, uint64_t Value) {
-  SD->AddressSize = Value;
+
+uint64_t MCAsmLayout::getSectionSize(const MCSectionData *SD) const {
+  // Empty sections have no size.
+  if (SD->getFragmentList().empty())
+    return 0;
+
+  // The logical size is the address space size minus any tail padding.
+  uint64_t Size = getSectionAddressSize(SD);
+  const MCAlignFragment *AF =
+    dyn_cast<MCAlignFragment>(&(SD->getFragmentList().back()));
+  if (AF && AF->hasOnlyAlignAddress())
+    Size -= getFragmentEffectiveSize(AF);
+
+  return Size;
 }
 
 /* *** */
@@ -157,9 +167,6 @@
   : Section(&_Section),
     Alignment(1),
     Address(~UINT64_C(0)),
-    Size(~UINT64_C(0)),
-    AddressSize(~UINT64_C(0)),
-    FileSize(~UINT64_C(0)),
     HasInstructions(false)
 {
   if (A)
@@ -438,7 +445,6 @@
 void MCAssembler::LayoutSection(MCAsmLayout &Layout,
                                 unsigned SectionOrderIndex) {
   MCSectionData &SD = *Layout.getSectionOrder()[SectionOrderIndex];
-  bool IsVirtual = getBackend().isVirtualSection(SD.getSection());
 
   ++stats::SectionLayouts;
 
@@ -458,25 +464,6 @@
 
   for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it)
     LayoutFragment(Layout, *it);
-
-  // Set the section sizes.
-  uint64_t Size = 0;
-  if (!SD.getFragmentList().empty()) {
-    MCFragment *F = &SD.getFragmentList().back();
-    Size = Layout.getFragmentOffset(F) + Layout.getFragmentEffectiveSize(F);
-  }
-  Layout.setSectionAddressSize(&SD, Size);
-  Layout.setSectionFileSize(&SD, IsVirtual ? 0 : Size);
-
-  // Handle OnlyAlignAddress bit.
-  if (!SD.getFragmentList().empty()) {
-    MCAlignFragment *AF =
-      dyn_cast<MCAlignFragment>(&SD.getFragmentList().back());
-    if (AF && AF->hasOnlyAlignAddress())
-      Size -= Layout.getFragmentEffectiveSize(AF);
-  }
-
-  Layout.setSectionSize(&SD, Size);
 }
 
 /// WriteFragmentData - Write the \arg F data to the output file.
@@ -948,8 +935,7 @@
 
   OS << "<MCSectionData";
   OS << " Alignment:" << getAlignment() << " Address:" << Address
-     << " Size:" << Size << " AddressSize:" << AddressSize
-     << " FileSize:" << FileSize << " Fragments:[\n      ";
+     << " Fragments:[\n      ";
   for (iterator it = begin(), ie = end(); it != ie; ++it) {
     if (it != begin()) OS << ",\n      ";
     it->dump();





More information about the llvm-commits mailing list