[llvm] 408e871 - MCAssembler: Merge fragmentNeedsRelaxation into relaxInstruction

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 6 17:39:29 PDT 2025


Author: Fangrui Song
Date: 2025-07-06T17:39:23-07:00
New Revision: 408e87184f8274e30d188a2fe198facf55243733

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

LOG: MCAssembler: Merge fragmentNeedsRelaxation into relaxInstruction

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCAssembler.h
    llvm/lib/MC/MCAssembler.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h
index 8261fd41a522b..1015992cedf29 100644
--- a/llvm/include/llvm/MC/MCAssembler.h
+++ b/llvm/include/llvm/MC/MCAssembler.h
@@ -109,9 +109,6 @@ class MCAssembler {
   /// (increased in size, in order to hold its value correctly).
   bool fixupNeedsRelaxation(const MCRelaxableFragment &, const MCFixup &) const;
 
-  /// Check whether the given fragment needs relaxation.
-  bool fragmentNeedsRelaxation(const MCRelaxableFragment &) const;
-
   void layoutSection(MCSection &Sec);
   /// Perform one layout iteration and return the index of the first stable
   /// section for subsequent optimization.

diff  --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index ee82383afcb3d..496d66b1876b2 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -863,34 +863,24 @@ bool MCAssembler::fixupNeedsRelaxation(const MCRelaxableFragment &F,
                                                    Resolved);
 }
 
-bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment &F) const {
-  assert(getBackendPtr() && "Expected assembler backend");
+bool MCAssembler::relaxInstruction(MCRelaxableFragment &F) {
+  assert(getEmitterPtr() &&
+         "Expected CodeEmitter defined for relaxInstruction");
   // If this inst doesn't ever need relaxation, ignore it. This occurs when we
   // are intentionally pushing out inst fragments, or because we relaxed a
   // previous instruction to one that doesn't need relaxation.
   if (!getBackend().mayNeedRelaxation(F.getInst(), *F.getSubtargetInfo()))
     return false;
 
+  bool DoRelax = false;
   for (const MCFixup &Fixup : F.getFixups())
-    if (fixupNeedsRelaxation(F, Fixup))
-      return true;
-
-  return false;
-}
-
-bool MCAssembler::relaxInstruction(MCRelaxableFragment &F) {
-  assert(getEmitterPtr() &&
-         "Expected CodeEmitter defined for relaxInstruction");
-  if (!fragmentNeedsRelaxation(F))
+    if ((DoRelax = fixupNeedsRelaxation(F, Fixup)))
+      break;
+  if (!DoRelax)
     return false;
 
   ++stats::RelaxedInstructions;
 
-  // FIXME-PERF: We could immediately lower out instructions if we can tell
-  // they are fully resolved, to avoid retesting on later passes.
-
-  // Relax the fragment.
-
   MCInst Relaxed = F.getInst();
   getBackend().relaxInstruction(Relaxed, *F.getSubtargetInfo());
 


        


More information about the llvm-commits mailing list