[llvm] 66518ad - [MC] Remove addFragment. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 29 17:26:56 PDT 2024


Author: Fangrui Song
Date: 2024-06-29T17:26:51-07:00
New Revision: 66518ad7fd3383d1f1b617914c0bc3437ac3a355

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

LOG: [MC] Remove addFragment. NFC

This was introduced in dcb71c06c7b059e313f22e46bc9c41343a03f1eb to help
migrate away raw `operator new` and refactor the fragment
representation.

This is now unneeded after `MCStreamer::CurFrag` and
`MCSection::CurFragList` refactoring.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCSection.h
    llvm/lib/MC/MCContext.cpp
    llvm/lib/MC/MCMachOStreamer.cpp
    llvm/lib/MC/MCWinCOFFStreamer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index e8e65750389c7..58ba34c07262b 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -198,18 +198,6 @@ class MCSection {
   iterator end() const { return {}; }
   bool empty() const { return !CurFragList->Head; }
 
-  void addFragment(MCFragment &F) {
-    // The formal layout order will be finalized in MCAssembler::layout.
-    if (CurFragList->Tail) {
-      CurFragList->Tail->Next = &F;
-      F.setLayoutOrder(CurFragList->Tail->getLayoutOrder() + 1);
-    } else {
-      CurFragList->Head = &F;
-      assert(F.getLayoutOrder() == 0);
-    }
-    CurFragList->Tail = &F;
-  }
-
   void dump() const;
 
   virtual void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,

diff  --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 1f23705a6101f..2fe8369016440 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -201,7 +201,8 @@ MCDataFragment *MCContext::allocInitialFragment(MCSection &Sec) {
   assert(!Sec.curFragList()->Head);
   auto *F = allocFragment<MCDataFragment>();
   F->setParent(&Sec);
-  Sec.addFragment(*F);
+  Sec.curFragList()->Head = F;
+  Sec.curFragList()->Tail = F;
   return F;
 }
 

diff  --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index e2f6508b9c89e..d67b95820a8a9 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -596,9 +596,7 @@ void MCMachOStreamer::createAddrSigSection() {
   MCSection *AddrSigSection =
       Asm.getContext().getObjectFileInfo()->getAddrSigSection();
   changeSection(AddrSigSection);
-  auto *Frag = getContext().allocFragment<MCDataFragment>();
-  Frag->setParent(AddrSigSection);
-  AddrSigSection->addFragment(*Frag);
+  auto *Frag = cast<MCDataFragment>(AddrSigSection->curFragList()->Head);
   // We will generate a series of pointer-sized symbol relocations at offset
   // 0x0. Set the section size to be large enough to contain a single pointer
   // (instead of emitting a zero-sized section) so these relocations are

diff  --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp
index c4c3570223e47..538244cb8ba6a 100644
--- a/llvm/lib/MC/MCWinCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp
@@ -205,9 +205,7 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
   changeSection(SXData);
   SXData->ensureMinAlignment(Align(4));
 
-  auto *F = getContext().allocFragment<MCSymbolIdFragment>(Symbol);
-  F->setParent(SXData);
-  SXData->addFragment(*F);
+  insert(getContext().allocFragment<MCSymbolIdFragment>(Symbol));
   getAssembler().registerSymbol(*Symbol);
   CSymbol->setIsSafeSEH();
 


        


More information about the llvm-commits mailing list