[llvm] 3ecefba - MC: Restore emitInstToData optimization

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 28 23:31:44 PDT 2025


Author: Fangrui Song
Date: 2025-07-28T23:31:39-07:00
New Revision: 3ecefba52d3ea7e0d028dd4b745766cb5627121f

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

LOG: MC: Restore emitInstToData optimization

Accidentally dropped by f36ce53adf9294556c5d5f5f55c484c923f0c286

Added: 
    

Modified: 
    llvm/lib/MC/MCObjectStreamer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 17d096858d76d..e82393a8477ea 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -435,17 +435,19 @@ void MCObjectStreamer::emitInstToData(const MCInst &Inst,
   bool MarkedLinkerRelaxable = false;
   for (auto &Fixup : Fixups) {
     Fixup.setOffset(Fixup.getOffset() + CodeOffset);
-    if (!Fixup.isLinkerRelaxable())
+    if (!Fixup.isLinkerRelaxable() || MarkedLinkerRelaxable)
       continue;
-    F->setLinkerRelaxable();
+    MarkedLinkerRelaxable = true;
+    // Set the fragment's order within the subsection for use by
+    // MCAssembler::relaxAlign.
+    auto *Sec = F->getParent();
+    if (!Sec->isLinkerRelaxable())
+      Sec->setLinkerRelaxable();
     // Do not add data after a linker-relaxable instruction. The 
diff erence
     // between a new label and a label at or before the linker-relaxable
     // instruction cannot be resolved at assemble-time.
-    if (!MarkedLinkerRelaxable) {
-      MarkedLinkerRelaxable = true;
-      getCurrentSectionOnly()->setLinkerRelaxable();
-      newFragment();
-    }
+    F->setLinkerRelaxable();
+    newFragment();
   }
   F->appendFixups(Fixups);
 }


        


More information about the llvm-commits mailing list