[llvm] eedc72b - MCSection: Replace DummyFragment with the Subsections[0] head fragment

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 1 01:12:11 PDT 2025


Author: Fangrui Song
Date: 2025-06-01T01:12:06-07:00
New Revision: eedc72b45e953bd21cb5c772b8fd24b414894042

URL: https://github.com/llvm/llvm-project/commit/eedc72b45e953bd21cb5c772b8fd24b414894042
DIFF: https://github.com/llvm/llvm-project/commit/eedc72b45e953bd21cb5c772b8fd24b414894042.diff

LOG: MCSection: Replace DummyFragment with the Subsections[0] head fragment

The dummy fragment is primarily used by MCAsmStreamer::emitLabel to
track the defined state. We can replace it with an arbitrary fragment.

Remove MCDummyFragment introduced for https://github.com/llvm/llvm-project/issues/24860

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCFragment.h
    llvm/include/llvm/MC/MCSection.h
    llvm/lib/MC/MCAssembler.cpp
    llvm/lib/MC/MCFragment.cpp
    llvm/lib/MC/MCSection.cpp
    llvm/lib/MC/MCSymbol.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h
index b0a39ffacccce..fdbfef28088d1 100644
--- a/llvm/include/llvm/MC/MCFragment.h
+++ b/llvm/include/llvm/MC/MCFragment.h
@@ -50,7 +50,6 @@ class MCFragment {
     FT_CVInlineLines,
     FT_CVDefRange,
     FT_PseudoProbe,
-    FT_Dummy
   };
 
 private:
@@ -111,13 +110,6 @@ class MCFragment {
   void dump() const;
 };
 
-class MCDummyFragment : public MCFragment {
-public:
-  explicit MCDummyFragment() : MCFragment(FT_Dummy, false) {}
-
-  static bool classof(const MCFragment *F) { return F->getKind() == FT_Dummy; }
-};
-
 /// Interface implemented by fragments that contain encoded instructions and/or
 /// data.
 ///

diff  --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index 6b301a002e45c..942d09bad5949 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -111,8 +111,6 @@ class MCSection {
   /// offset between two locations may not be fully resolved.
   bool LinkerRelaxable : 1;
 
-  MCDummyFragment DummyFragment;
-
   // Mapping from subsection number to fragment list. At layout time, the
   // subsection 0 list is replaced with concatenated fragments from all
   // subsections.
@@ -182,8 +180,7 @@ class MCSection {
   bool isLinkerRelaxable() const { return LinkerRelaxable; }
   void setLinkerRelaxable() { LinkerRelaxable = true; }
 
-  const MCDummyFragment &getDummyFragment() const { return DummyFragment; }
-  MCDummyFragment &getDummyFragment() { return DummyFragment; }
+  MCFragment &getDummyFragment() { return *Subsections[0].second.Head; }
 
   FragList *curFragList() const { return CurFragList; }
   iterator begin() const { return iterator(CurFragList->Head); }

diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 097096304a7e9..5fde90e6abb7e 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -300,8 +300,6 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
     return cast<MCCVDefRangeFragment>(F).getContents().size();
   case MCFragment::FT_PseudoProbe:
     return cast<MCPseudoProbeAddrFragment>(F).getContents().size();
-  case MCFragment::FT_Dummy:
-    llvm_unreachable("Should not have been added");
   }
 
   llvm_unreachable("invalid fragment kind");
@@ -767,8 +765,6 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
     OS << PF.getContents();
     break;
   }
-  case MCFragment::FT_Dummy:
-    llvm_unreachable("Should not have been added");
   }
 
   assert(OS.tell() - Start == FragmentSize &&
@@ -846,7 +842,7 @@ void MCAssembler::layout() {
 
     // Chain together fragments from all subsections.
     if (Sec.Subsections.size() > 1) {
-      MCDummyFragment Dummy;
+      MCDataFragment Dummy;
       MCFragment *Tail = &Dummy;
       for (auto &[_, List] : Sec.Subsections) {
         assert(List.Head);

diff  --git a/llvm/lib/MC/MCFragment.cpp b/llvm/lib/MC/MCFragment.cpp
index bf8f8322a8a9d..aa4dec0a8e9d9 100644
--- a/llvm/lib/MC/MCFragment.cpp
+++ b/llvm/lib/MC/MCFragment.cpp
@@ -72,9 +72,6 @@ void MCFragment::destroy() {
     case FT_PseudoProbe:
       cast<MCPseudoProbeAddrFragment>(this)->~MCPseudoProbeAddrFragment();
       return;
-    case FT_Dummy:
-      cast<MCDummyFragment>(this)->~MCDummyFragment();
-      return;
   }
 }
 
@@ -119,7 +116,6 @@ LLVM_DUMP_METHOD void MCFragment::dump() const {
   case MCFragment::FT_PseudoProbe:
     OS << "MCPseudoProbe";
     break;
-  case MCFragment::FT_Dummy: OS << "MCDummyFragment"; break;
   }
 
   OS << "<MCFragment " << (const void *)this << " LayoutOrder:" << LayoutOrder
@@ -241,8 +237,6 @@ LLVM_DUMP_METHOD void MCFragment::dump() const {
     OS << " AddrDelta:" << OF->getAddrDelta();
     break;
   }
-  case MCFragment::FT_Dummy:
-    break;
   }
   OS << ">";
 }

diff  --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 8409eebad404b..0e64c887e91b9 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -24,7 +24,6 @@ MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText,
     : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
       HasLayout(false), IsRegistered(false), IsText(IsText),
       IsVirtual(IsVirtual), LinkerRelaxable(false), Name(Name), Variant(V) {
-  DummyFragment.setParent(this);
   // The initial subsection number is 0. Create a fragment list.
   CurFragList = &Subsections.emplace_back(0u, FragList{}).second;
 }

diff  --git a/llvm/lib/MC/MCSymbol.cpp b/llvm/lib/MC/MCSymbol.cpp
index 100f693a739e4..5cba901d33d5e 100644
--- a/llvm/lib/MC/MCSymbol.cpp
+++ b/llvm/lib/MC/MCSymbol.cpp
@@ -22,7 +22,7 @@
 using namespace llvm;
 
 // Only the address of this fragment is ever actually used.
-static MCDummyFragment SentinelFragment;
+static MCDataFragment SentinelFragment;
 
 // Sentinel value for the absolute pseudo fragment.
 MCFragment *MCSymbol::AbsolutePseudoFragment = &SentinelFragment;


        


More information about the llvm-commits mailing list