[llvm] ecf0cbd - MCFragment: Refactor LEB

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 19 09:59:32 PDT 2025


Author: Fangrui Song
Date: 2025-07-19T09:59:27-07:00
New Revision: ecf0cbda18d41939952ac1ee5a320e8920cf9e50

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

LOG: MCFragment: Refactor LEB

* Deduplicate creation of SLEB128/ULEB128 with makeLEB.
* Call newFragment to prepare for removing getOrCreateDataFragment.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCSection.h
    llvm/lib/MC/MCObjectStreamer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index 313071ec75033..63a23b1eb034d 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -443,6 +443,12 @@ class MCFragment {
   }
 
   //== FT_LEB functions
+  void makeLEB(bool IsSigned, const MCExpr *Value) {
+    assert(Kind == FT_Data);
+    Kind = MCFragment::FT_LEB;
+    u.leb.IsSigned = IsSigned;
+    u.leb.Value = Value;
+  }
   const MCExpr &getLEBValue() const {
     assert(Kind == FT_LEB);
     return *u.leb.Value;
@@ -455,10 +461,6 @@ class MCFragment {
     assert(Kind == FT_LEB);
     return u.leb.IsSigned;
   }
-  void setLEBSigned(bool S) {
-    assert(Kind == FT_LEB);
-    u.leb.IsSigned = S;
-  }
 
   //== FT_DwarfFrame functions
   const MCExpr &getDwarfAddrDelta() const {

diff  --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index d5b8f22463894..f61dda6d248b5 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -215,9 +215,8 @@ void MCObjectStreamer::emitULEB128Value(const MCExpr *Value) {
     return;
   }
   auto *F = getOrCreateDataFragment();
-  F->Kind = MCFragment::FT_LEB;
-  F->setLEBSigned(false);
-  F->setLEBValue(Value);
+  F->makeLEB(false, Value);
+  newFragment();
 }
 
 void MCObjectStreamer::emitSLEB128Value(const MCExpr *Value) {
@@ -227,9 +226,8 @@ void MCObjectStreamer::emitSLEB128Value(const MCExpr *Value) {
     return;
   }
   auto *F = getOrCreateDataFragment();
-  F->Kind = MCFragment::FT_LEB;
-  F->setLEBSigned(true);
-  F->setLEBValue(Value);
+  F->makeLEB(true, Value);
+  newFragment();
 }
 
 void MCObjectStreamer::emitWeakReference(MCSymbol *Alias,


        


More information about the llvm-commits mailing list