[llvm] 939f927 - MCSymbol: Split FragmentAndHasName to Fragment and HasName

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat May 13 18:47:39 PDT 2023


Author: Fangrui Song
Date: 2023-05-13T18:47:29-07:00
New Revision: 939f927dfc38347dc2aa3e80f5c506b7a4875d69

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

LOG: MCSymbol: Split FragmentAndHasName to Fragment and HasName

The bit fields have plent of spare bits. Just reserve one for HasName so that we
can access Fragment without bitwise operations. Fragment is commonly accessed.
This change makes my x86-64 release build 5KiB smaller.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCSymbol.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCSymbol.h b/llvm/include/llvm/MC/MCSymbol.h
index 8954960e3b8c7..c1fad4481c190 100644
--- a/llvm/include/llvm/MC/MCSymbol.h
+++ b/llvm/include/llvm/MC/MCSymbol.h
@@ -76,11 +76,11 @@ class MCSymbol {
   ///
   /// If this is a fragment, then it gives the fragment this symbol's value is
   /// relative to, if any.
-  ///
-  /// For the 'HasName' integer, this is true if this symbol is named.
-  /// A named symbol will have a pointer to the name allocated in the bytes
-  /// immediately prior to the MCSymbol.
-  mutable PointerIntPair<MCFragment *, 1> FragmentAndHasName;
+  mutable MCFragment *Fragment = nullptr;
+
+  /// True if this symbol is named.  A named symbol will have a pointer to the
+  /// name allocated in the bytes immediately prior to the MCSymbol.
+  unsigned HasName : 1;
 
   /// IsTemporary - True if this is an assembler temporary label, which
   /// typically does not survive in the .o file's symbol table.  Usually
@@ -164,7 +164,7 @@ class MCSymbol {
         Kind(Kind), IsUsedInReloc(false), SymbolContents(SymContentsUnset),
         CommonAlignLog2(0), Flags(0) {
     Offset = 0;
-    FragmentAndHasName.setInt(!!Name);
+    HasName = !!Name;
     if (Name)
       getNameEntryPtr() = Name;
   }
@@ -187,7 +187,7 @@ class MCSymbol {
 
   /// Get a reference to the name field.  Requires that we have a name
   const StringMapEntry<bool> *&getNameEntryPtr() {
-    assert(FragmentAndHasName.getInt() && "Name is required");
+    assert(HasName && "Name is required");
     NameEntryStorageTy *Name = reinterpret_cast<NameEntryStorageTy *>(this);
     return (*(Name - 1)).NameEntry;
   }
@@ -201,7 +201,7 @@ class MCSymbol {
 
   /// getName - Get the symbol name.
   StringRef getName() const {
-    if (!FragmentAndHasName.getInt())
+    if (!HasName)
       return StringRef();
 
     return getNameEntryPtr()->first();
@@ -272,11 +272,11 @@ class MCSymbol {
   /// Mark the symbol as defined in the fragment \p F.
   void setFragment(MCFragment *F) const {
     assert(!isVariable() && "Cannot set fragment of variable");
-    FragmentAndHasName.setPointer(F);
+    Fragment = F;
   }
 
   /// Mark the symbol as undefined.
-  void setUndefined() { FragmentAndHasName.setPointer(nullptr); }
+  void setUndefined() { Fragment = nullptr; }
 
   bool isELF() const { return Kind == SymbolKindELF; }
 
@@ -393,11 +393,9 @@ class MCSymbol {
   }
 
   MCFragment *getFragment(bool SetUsed = true) const {
-    MCFragment *Fragment = FragmentAndHasName.getPointer();
     if (Fragment || !isVariable())
       return Fragment;
     Fragment = getVariableValue(SetUsed)->findAssociatedFragment();
-    FragmentAndHasName.setPointer(Fragment);
     return Fragment;
   }
 


        


More information about the llvm-commits mailing list